Where does pip install Python packages on Windows, macOS, and Linux? | A1Lab@MZeeshanM to PythonEnglish • 3 days ago

Where does pip install Python packages on Windows, macOS, and Linux?

message-square
0

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 pip instead of bare pip:
    • When multiple Python versions or virtual environments exist on your PATH, bare pip may belong to a different interpreter than python. Running python -m pip install <pkg> guarantees packages land in the exact site-packages directory used by that python executable.
  • Virtual environments (venv, conda, uv) isolate packages inside the project folder:
    • Windows (venv): <project>\.venv\Lib\site-packages (capital Lib, no version number in the directory name).
    • macOS & Linux (venv): <project>/.venv/lib/python3.X/site-packages (lowercase lib, includes python3.X version subdirectory).
  • User-level installs (--user or when global site-packages is read-only):
    • Passing --user (or running pip without 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-packages for Microsoft Store Python).
      • macOS (Framework Python): ~/Library/Python/3.X/lib/python/site-packages.
      • Linux: ~/.local/lib/python3.X/site-packages.
  • PEP 668 (externally-managed-environment) on modern Linux and Homebrew macOS:
    • Modern Debian/Ubuntu, Fedora, and Homebrew Python installations block global pip install outside virtual environments (error: externally-managed-environment) to prevent breaking OS system tools. Create and activate a virtual environment (python -m venv .venv) or use pipx / uv for CLI tools.
  • 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 --user installs.

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/