How to Find the Location of Your Python Site-Packages Directory
Python utilizes both global and per user site-packages directories to manage installed packages. Let us explore the methods to locate these directories:
Global Site-Packages Directories
These directories, often referred to as "dist-packages," are listed in the sys.path variable. To display these directories, run the following command:
python -m site
For a more compact list, use getsitepackages from the site module within Python code:
python -c 'import site; print(site.getsitepackages())'
In Python 3, consider using the sysconfig module:
python3 -c 'import sysconfig; print(sysconfig.get_paths()["purelib"])'
Per User Site-Packages Directories
These directories, as per PEP 370, hold locally installed packages. To find the per user directory, execute:
python -m site --user-site
If this returns a non-existent directory, examine Python's exit status and refer to python -m site --help for further information.
Practical Tips
The above is the detailed content of Where Are My Python Site-Packages Directories Located?. For more information, please follow other related articles on the PHP Chinese website!