How to find out the Python library installation path?

library-path, python, setuptools

Solution

If the packages have already been installed, you could just import them, and look into their `__file__` property:

>>> import mymodule
>>> print mymodule.__file__
'/path/to/mymodule.py'

Problem

For installing third-party Python packages I have used a setup.py script that uses setuptools.setup() to install a bunch of packages. After the installation I can find these packages on one machine under /usr/local/lib/python2.7/dist-packages and on another machine under /usr/lib/python2.7/site-packages. Now I want to write a Python script that finds out where the third-party packages have been installed. How can I do that? 1) sys.prefix=sys.exec_prefix is on both machines "/usr". 2) The python executable is on both machines /usr/bin/python. 3) distutils.sysconfig.get_python_lib() is /usr/lib/python2.7/dist-packages ("local" is missing) on one machine and /usr/lib/python2.7/site-packages on the other machine.

Original source

Related problems