Run python -m site in your terminal or inspect sysconfig.get_paths()["purelib"] (or site.getsitepackages()) inside Python—making sure to run the command with the exact Python interpreter or active virtual environment whose site-packages folder you want to locate.
Basic Example
# 1. Terminal one-liner: Prints sys.path, USER_SITE, and ENABLE_USER_SITE status
python -m site
# 2. Print ONLY the user-specific site-packages path
python -m site --user-site
import site
import sysconfig
# 3. Recommended in Python scripts: sysconfig (works in global Python AND venvs)
print(sysconfig.get_paths()["purelib"]) # Pure-Python packages directory
print(sysconfig.get_paths()["platlib"]) # Platform-specific C-extension packages directory
# 4. List all global/environment site-packages directories
print(site.getsitepackages())
# 5. Locate the exact site-packages directory containing a specific installed library
import requests
print(requests.__file__) # e.g., "/path/to/.venv/lib/python3.12/site-packages/requests/__init__.py"
Key Details & Edge Cases
sysconfig.get_paths()["purelib"]vs.site.getsitepackages():sysconfig.get_paths()["purelib"]returns the exact primarysite-packagesstring across Windows, macOS, Linux, virtual environments (venv), and Conda environments without platform inconsistencies.site.getsitepackages()returns alist[str]that can include extra system directories (such as/usr/lib/python3/dist-packagesalongside/usr/local/lib/python3.12/dist-packageson Debian/Ubuntu Linux).
- Debian / Ubuntu
dist-packagesvs.site-packages:- On Debian and Ubuntu systems, the OS-bundled Python installs third-party APT and global
pippackages intodist-packages(/usr/lib/python3/dist-packagesor/usr/local/lib/python3.X/dist-packages), whereas virtual environments (venv) created on those same machines always usesite-packages(.venv/lib/python3.X/site-packages).
- On Debian and Ubuntu systems, the OS-bundled Python installs third-party APT and global
- Windows vs. POSIX directory layouts:
- Windows:
<prefix>\Lib\site-packages(e.g.,C:\Users\Alice\project\.venv\Lib\site-packages). - Linux / macOS:
<prefix>/lib/pythonX.Y/site-packages(e.g.,/home/alice/project/.venv/lib/python3.12/site-packages).
- Windows:
- User site-packages (
--userinstalls): Packages installed withpip install --usergo into a separate user-scoped folder (site.getusersitepackages()), typically~/.local/lib/pythonX.Y/site-packageson Linux/macOS or%APPDATA%\Python\PythonXY\site-packageson Windows—note that standardvenvenvironments disableUSER_SITE(ENABLE_USER_SITE: False) by default for isolation. - Finding where a specific package lives (
pip show <pkg>): If multiplesite-packagesdirectories exist onsys.path, runpython -m pip show <package-name>and check theLocation:field to see which exact directory loaded that package.
Comparison of site-packages Lookup Methods
| Method | Environment | Output Type | Typical Output Example | Best Used When |
|---|---|---|---|---|
python -m site |
Terminal CLI | Printed diagnostic report | sys.path = [...], USER_SITE: '...' |
Quickly inspecting all active search paths and user-site status from a shell. |
sysconfig.get_paths()["purelib"] |
Python code | str |
"/app/.venv/lib/python3.12/site-packages" |
Programmatically resolving the primary site-packages path reliably across all OSes and venvs. |
site.getsitepackages() |
Python code | list[str] |
["/usr/local/lib/python3.12/dist-packages", ...] |
Enumerating all environment-level site/dist-packages directories. |
site.getusersitepackages() |
Python code | str |
"/home/user/.local/lib/python3.12/site-packages" |
Locating user-level (pip install --user) packages outside a virtual environment. |
python -m pip show <pkg> |
Terminal CLI | Metadata block (Location: ...) |
Location: /app/.venv/lib/python3.12/site-packages |
Verifying which exact site-packages folder a specific installed package resides in. |
You must log in or register to comment.
