Are the paths to the python standard library and to the dist-packages different for different linux distributions(Debian, Redhat, Slackware, …)?

StackOverflow https://stackoverflow.com/questions/11825516

Frage

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.

Edit1

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

Edit2

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.

War es hilfreich?

Lösung

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.

Andere Tipps

You can read more into this subject from here http://www.aosabook.org/en/packaging.html, $ it talks allot about packaging and library locations if we want to deploy a package to the software repository.

I have talked a little bit about this in my blog, please have a look and give me some feedback

http://insidepython.wordpress.com/2012/08/03/quickintro/

Cheers

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top