Locate Your Python site-packages Directory
Determining the location of your Python site-packages directory is crucial for package management. This directory holds user-installed packages, and its location varies depending on the scope.
Global site-packages Directory
- Listed in sys.path when running python -m site
- For a concise list, use python -c 'import site; print(site.getsitepackages())'
- In Python 3, use sysconfig.get_paths()["purelib"] from python3 -c 'import sysconfig'
Per User site-packages Directory (PEP 370)
- Accessible with python -m site --user-site
- Check for a non-existing directory and Python's exit status
- Install user packages with pip list --user or pip freeze --user
Practical Tips
- Identify package locations with package.__path__
- Trace module locations with module.__file__
- Use pip show package to display Debian-style package information, including the installation path
The above is the detailed content of How Can I Find My Python site-packages Directory?. For more information, please follow other related articles on the PHP Chinese website!