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 Topic
- 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 Answer
There are two types of site-packages directories, global and per user.
Global site-packages ("dist-packages") directories are listed in
sys.path
when you run:For a more concise list run
getsitepackages
from the site module in Python code:Note: With virtualenvs getsitepackages is not available,
sys.path
from 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 --help
for explanations.Hint: Running
pip list --user
orpip freeze --user
gives 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: