My question assumes you are using the same python versions on those different linux distributions. I also exclude virtual environments from my question.
I use the Debian based distribution Ubuntu. There the path to the python standard library (the modules/packages written in python) is /usr/lib/python2.7
. The path to "external" python packages is /usr/local/lib/python2.7/dist-packages
.
A system independent way to get these paths is greatly appreciated.
I found:
>>> from distutils.sysconfig import get_python_lib
>>> print get_python_lib()
/usr/local/lib/python2.7/dist-packages
and
>>> print get_python_lib(standard_lib=True)
/usr/lib/python2.7
I think the approach in the first edit is deprecated since I can only find this up and untill the python2.5 docs. The new approach (in 2.7 docs):
>>> import sysconfig
>>> sysconfig.get_path_names()
('stdlib', 'platstdlib', 'purelib', 'platlib', 'include', 'scripts', 'data')
>>> print sysconfig.get_path('platlib')
/usr/local/lib/python2.7/dist-packages
I haven't found yet how to find /usr/lib/python2.7
with sysconfig. For now I'll work with the deprecated approach and proceed under the assumption that this yields the desired results.
Yes it's different, in CentOS 5.6, for example, python external modules are placed in /usr/lib/python2.6/site-packages
. Actually dist-packages
is debian specific directory.