I’m a developer for the Spack package manager. Spack is similar to Conda in the sense that it can install both Python and non-Python libraries, and similar to Nix in the sense that each package is installed to a unique installation prefix. Spack supports reusing system installations of Python (built with apt, yum, conda, etc.).
When dealing with Python installations, we’ve noticed that third-party Python libraries may be installed in one of several directories:
-
lib/pythonX.Y/site-packageson most POSIX systems -
lib64/pythonX.Y/site-packageson RHEL/CentOS/Fedora with system Python -
lib/pythonX/dist-packageson Debian/Ubuntu with system Python -
lib/python/site-packageson macOS with framework Python -
Lib/site-packageson Windows - others?
We would like to know this directory ahead of time so that we can set PYTHONPATH appropriately. My question is, when installing a Python library, how does the site-packages directory get decided? Does it depend on the installation method? For example, do all of the following make the same decisions:
- distutils: legacy
python setup.py install(deprecated) - setuptools: legacy
python setup.py install(deprecated) - pip:
pip install - installer:
python -c 'import installer; installer.install(...)' - others?
So far the most reliable method I’ve found is to query distutils.sysconfig.get_python_lib(...) (deprecated) or sysconfig.get_path(...). Is this how these installation methods make the decision? How do these installation methods decide whether to use purelib or platlib?
Note: I originally opened this question on the setuptools GitHub but it seems like this question is better asked to the broader community.