Closed ionelmc closed 3 years ago
Dooh! 🤦♂️
I just found site.getsitepackages() and wonder if it does what you want?
$ python3.10 -Wall
Python 3.10.0b1 (default, May 4 2021, 14:26:39) [GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.sysconfig import get_python_lib
<stdin>:1: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
<stdin>:1: DeprecationWarning: The distutils.sysconfig module is deprecated, use sysconfig instead
>>> get_python_lib()
'/usr/lib/python3.10/site-packages'
>>> from site import getsitepackages
>>> getsitepackages()
['/usr/lib/python3.10/site-packages']
seems to work on e.g. Ubuntu 20.04 too:
>>> import site
>>> site.getsitepackages()
['/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.8/dist-packages']
Yes, I know about it - it's actually used:
if hasattr(site, 'getsitepackages'):
SITE_PACKAGES_PATHS.update(site.getsitepackages())
But I have chosen to not solely rely on it because everyone messes with that site.py file (distro customizations, virtualenv implementing workarounds or whatever). It wouldn't include distro-packages for sure.
Ref #97