pip installs packages into the active Python environment’s site-packages directory—which resolves to <venv>/Lib/site-packages (Windows) or <venv>/lib/pythonX.Y/site-packages (macOS/Linux) inside a virtual environment, or into a platform-specific global/user site-packages folder when invoked outside a virtual environment—and you can inspect the exact active path anytime with python -m site or pip show <package>.
Basic Example
# 1. Recommended: Print the exact site-packages directory for your active Python interpreter
python -m site
# 2. Check the exact installation location of a specific installed package
python -m pip show requests
# Output includes: Location: /path/to/your/env/lib/python3.12/site-packages
# 3. Print pure-Python and platform-specific install paths programmatically
python -c "import sysconfig; print(sysconfig.get_paths()['purelib'])"
Key Details & Edge Cases
- Always run
python -m pipinstead of barepip:- When multiple Python versions or virtual environments exist on your
PATH, barepipmay belong to a different interpreter thanpython. Runningpython -m pip install <pkg>guarantees packages land in the exactsite-packagesdirectory used by thatpythonexecutable.
- When multiple Python versions or virtual environments exist on your
- Virtual environments (
venv,conda,uv) isolate packages inside the project folder:- Windows (
venv):<project>\.venv\Lib\site-packages(capitalLib, no version number in the directory name). - macOS & Linux (
venv):<project>/.venv/lib/python3.X/site-packages(lowercaselib, includespython3.Xversion subdirectory).
- Windows (
- User-level installs (
--useror when globalsite-packagesis read-only):- Passing
--user(or runningpipwithout admin/root privileges on Windows or older Linux/macOS setups) installs into the per-user site directory (site.USER_SITE):- Windows:
%APPDATA%\Python\Python3X\site-packages(or%LOCALAPPDATA%\Packages\PythonSoftwareFoundation...\site-packagesfor Microsoft Store Python). - macOS (Framework Python):
~/Library/Python/3.X/lib/python/site-packages. - Linux:
~/.local/lib/python3.X/site-packages.
- Windows:
- Passing
- PEP 668 (
externally-managed-environment) on modern Linux and Homebrew macOS:- Modern Debian/Ubuntu, Fedora, and Homebrew Python installations block global
pip installoutside virtual environments (error: externally-managed-environment) to prevent breaking OS system tools. Create and activate a virtual environment (python -m venv .venv) or usepipx/uvfor CLI tools.
- Modern Debian/Ubuntu, Fedora, and Homebrew Python installations block global
- Where executable CLI scripts (
pytest,black,uvicorn) are placed:- Console entry-point scripts do not go into
site-packages—they go into<venv>\Scripts\(Windows) or<venv>/bin/(macOS/Linux), and into~/.local/bin(Linux),~/Library/Python/3.X/bin(macOS), or%APPDATA%\Python\Python3X\Scripts(Windows) for--userinstalls.
- Console entry-point scripts do not go into
Comparison of Default pip Installation Paths by OS & Environment
| Environment Type | Windows Path | macOS Path | Linux Path |
|---|---|---|---|
Virtual Environment (venv) (Recommended) |
<venv>\Lib\site-packages |
<venv>/lib/python3.X/site-packages |
<venv>/lib/python3.X/site-packages |
User Install (--user) |
%APPDATA%\Python\Python3X\site-packages |
~/Library/Python/3.X/lib/python/site-packages |
~/.local/lib/python3.X/site-packages |
| System / Global Python | C:\Users\<user>\AppData\Local\Programs\Python\Python3X\Lib\site-packages |
/Library/Frameworks/Python.framework/Versions/3.X/lib/python3.X/site-packages (or /opt/homebrew/lib/python3.X/site-packages) |
/usr/local/lib/python3.X/dist-packages (Debian/Ubuntu) or .../site-packages (RHEL/Fedora) |
| CLI Entry-Point Scripts | <prefix>\Scripts\ |
<prefix>/bin/ |
<prefix>/bin/ |
You must log in or register to comment.
