Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 572
Bentley4 Avatar asked Aug 06 '12 09:08

Bentley4


People also ask

Does Linux have python installed by default?

On Linux. Python comes preinstalled on most Linux distributions, and is available as a package on all others. However there are certain features you might want to use that are not available on your distro's package. You can easily compile the latest version of Python from source.

Where is Python installed in Debian?

On Debian 10, the binary for Python 2 is located at /usr/bin/python , and the binary for Python 3 is located at /usr/bin/python3 . In this guide, you updated from Python 3.7 to Python 3.9 using the Debian Testing repository.

What is usr lib python3 Dist packages?

/usr/lib/python3/dist-packages contains non-host-specific modules installed by the system with the package manager, for example on Ubuntu with sudo apt install safeeyes .

Where do python packages get installed on ubuntu?

A non-Debian Python installation, such as Python compiled from source, will install Python packages into /usr/local/lib/pythonX. Y/site-packages by default, where X.Y is your Python version (such as 2.7 ).


2 Answers

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.

like image 55
Fedor Gogolev Avatar answered Nov 15 '22 16:11

Fedor Gogolev


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

like image 40
j0N45 Avatar answered Nov 15 '22 17:11

j0N45