bpo-41376: Correct the documentation on site.getusersitepackages()
regarding respecting PYTHONNOUSERSITE by pelson · Pull Request #21602 · python/cpython (original) (raw)
site.getusersitepackages()
returns the location of the user-specific site-packages directory
whether or not it exists, or is added to the sys.path
. We can see this easily with:
$ python -c "import site; print(site.getusersitepackages())"
/home/user/.local/lib/python3.7/site-packages
$ python -s -c "import site; print(site.getusersitepackages())"
/home/user/.local/lib/python3.7/site-packages
This is even true when the user-specific site-packages doesn't exist, as is demonstrated by:
$ python -m site
sys.path = [
'/home/user/conda/lib/python37.zip',
'/home/user/conda/lib/python3.7',
'/home/user/conda/lib/python3.7/lib-dynload',
'/home/user/conda/lib/python3.7/site-packages',
]
USER_BASE: '/home/user/.local' (exists)
USER_SITE: '/home/user/.local/lib/python3.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: True
$ python -s -m site
sys.path = [
'/home/user/conda/lib/python37.zip',
'/home/user/conda/lib/python3.7',
'/home/user/conda/lib/python3.7/lib-dynload',
'/home/user/conda/lib/python3.7/site-packages',
]
USER_BASE: '/home/user/.local' (exists)
USER_SITE: '/home/user/.local/lib/python3.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: False
It was not practical to update the function to return None if user-specific site-packages are disabled (i.e. update the function to reflect the existing documentation), since there are other uses of the function which are relying on this behaviour (e.g. python -m site
) and it would amount to a breaking change.