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.
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.
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.
/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 .
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 ).
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With