Get installed package location (not local)

83 Views Asked by At

I need to get the location of an installed package (i.e. from "site-packages" or "dist-packages"), but I may be inside the package's directory itself.

I have tried everything from both of these questions, and some problems inevitably arise.

I have tried pip.get_installed_distributions(), and this is very close, but there is no guarantee that the package will have been installed with pip. If the package is not installed with pip, then get_installed_distributions() doesn't return the package.

1

There are 1 best solutions below

3
On

How about:

python -c 'import module; print module.__file__'

E.g:

$ python -c 'import ssl; print ssl.__file__'
/usr/lib64/python2.7/ssl.pyc

Compare to:

$ python -c 'import requests; print requests.__file__'
/home/lars/env/common/lib/python2.7/site-packages/requests/__init__.pyc