How do I find the location of my site-packages directory?
Python - How to find the location of the Python site-packages directory
installationpython
Related Question
- Python - How to safely create a nested directory in Python
- Python - How to get the current time in Python
- Python - How to upgrade all Python packages with pip
- Python - How to list all files of a directory
- Python - Find all files in a directory with extension .txt in Python
- Python - How to install packages using pip according to the requirements.txt file from a local directory
- Python - How to find if directory exists in Python
Best Solution
There are two types of site-packages directories, global and per user.
Global site-packages ("dist-packages") directories are listed in
sys.pathwhen you run:For a more concise list run
getsitepackagesfrom the site module in Python code:Note: With virtualenvs getsitepackages is not available,
sys.pathfrom above will list the virtualenv's site-packages directory correctly, though. In Python 3, you may use the sysconfig module instead:The per user site-packages directory (PEP 370) is where Python installs your local packages:
If this points to a non-existing directory check the exit status of Python and see
python -m site --helpfor explanations.Hint: Running
pip list --userorpip freeze --usergives you a list of all installed per user site-packages.Practical Tips
<package>.__path__lets you identify the location(s) of a specific package: (details)<module>.__file__lets you identify the location of a specific module: (difference)Run
pip show <package>to show Debian-style package information: