How to Locate Your Python site-packages Directory
Finding the location of your Python site-packages directory, where your installed third-party packages reside, is crucial for package management. There are two primary types of site-packages directories: global and per-user.
Global Site-Packages Directories
These directories are listed in sys.path. To view them:
python -m site
For a more compact list, use site module's getsitepackages:
python -c 'import site; print(site.getsitepackages())'
Caution: In virtual environments, getsitepackages may not be available. Instead, use:
python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'
Per-User Site-Packages Directories
These directories are where Python installs your local packages. To find their location:
python -m site --user-site
Practical Tips
<package>.__path__
<module>.__file__
pip show <package>
The above is the detailed content of Where is My Python site-packages Directory Located?. For more information, please follow other related articles on the PHP Chinese website!