Search code examples
pythonpython-3.xpython-os

Find path of a package (e.g. pandas) in Python


Is there a way to programmatically find the location of a python package once it is imported?

For example:

import os

import pandas

os.get_package_directory(panda)
>>> C:\Users\username\miniconda3\pkgs\pandas-1.0.5-py37h47e9c7a_0


Solution

  • It's been a while since I've done this, but try this:

    import pandas
    print(pandas.__file__)