Python
Pip
Package Installation
Programming
Software Development

Where does pip install packages? (Windows, macOS, Linux)

Codemia Knowledge Hub ·

pip installs packages into the site-packages directory of the Python interpreter it belongs to. The exact path depends on the operating system, whether a virtual environment is active, and whether you used --user. Instead of memorizing OS conventions, ask Python: python -m site lists the directories, and python -m pip show <package> shows where a given package landed.

pip installs for one specific interpreter

Every Python interpreter has its own site-packages directory. pip install requests puts the files in the site-packages of whichever interpreter that pip belongs to.

The usual source of confusion is a pip tied to one interpreter while your code runs under another. Invoking pip through Python avoids that:

bash
# Always use this form to guarantee pip matches your interpreter
python -m pip install requests

This guarantees you are using the pip bundled with the exact python binary you are calling.

Finding the install location

python -m site

Prints all site-packages directories for the current interpreter, including sys.path, the user site-packages and the global site-packages:

bash
python -m site

From a Python script

For a precise, parseable answer:

python
1import site
2import sys
3
4print("Interpreter:", sys.executable)
5print("User site-packages:", site.getusersitepackages())
6for path in site.getsitepackages():
7    print("Global site-packages:", path)

pip show for one package

bash
python -m pip show requests

The Location: field gives the directory. You can also check from inside Python:

python
import requests
print(requests.__file__)
# e.g., /usr/lib/python3.11/site-packages/requests/__init__.py

Typical paths on Windows, macOS and Linux

ContextTypical Path (Linux/macOS)Typical Path (Windows)
System/global install/usr/lib/python3.X/site-packagesC:\Python3X\Lib\site-packages
Homebrew Python (macOS)/opt/homebrew/lib/python3.X/site-packagesN/A
--user install~/.local/lib/python3.X/site-packages%APPDATA%\Python\Python3X\site-packages
Virtual environment.venv/lib/python3.X/site-packages.venv\Lib\site-packages
Conda environment~/miniconda3/envs/myenv/lib/python3.X/site-packagesC:\Users\you\miniconda3\envs\myenv\Lib\site-packages

These vary by distribution and Python build, so verify with python -m site instead of hard-coding them.

Inside a virtual environment

With a virtual environment activated, pip installs into that environment's own site-packages, fully isolated from the system Python:

bash
1# Create and activate a virtual environment
2python3 -m venv .venv
3source .venv/bin/activate      # Linux/macOS
4# .venv\Scripts\activate       # Windows
5
6# Verify pip points to the venv
7python -m pip --version
8# pip 23.x from .venv/lib/python3.11/site-packages/pip (python 3.11)
9
10# Install a package
11python -m pip install requests
12
13# Confirm its location
14python -m pip show requests
15# Location: /home/user/project/.venv/lib/python3.11/site-packages

Deactivating the environment points python and pip back at the system versions. Packages installed inside the venv are not visible outside it, and vice versa.

With the --user flag

When you cannot write to the global site-packages (common on shared servers, or when the OS package manager manages the system Python), --user installs to a per-user directory:

bash
python -m pip install --user requests

On Linux and macOS this is typically ~/.local/lib/python3.X/site-packages. Query it with:

bash
python -m site --user-site

--user and virtual environments are mutually exclusive. Inside a venv, --user is ignored or raises an error, depending on the pip version.

Packages and command-line scripts go to different places

A package that ships command-line tools (like black, flask or pytest) installs into two locations:

bash
python -m pip install black
WhatWhereExample
Python packagesite-packages/black/The importable library
CLI scriptbin/ (Linux/macOS) or Scripts/ (Windows)The black command you run in the terminal

That is why an import can succeed while the command fails with "command not found": the bin/ or Scripts/ directory may not be on your PATH.

bash
1# Find where scripts are installed
2python -c "import sysconfig; print(sysconfig.get_path('scripts'))"
3
4# Or check directly
5which black               # Linux/macOS
6where black               # Windows

"Module not found" after a successful install

If pip install succeeds but import fails, you almost certainly have an interpreter mismatch. Check:

bash
1# Check which pip you used
2python -m pip --version
3
4# Check which python you are running
5python --version
6which python     # Linux/macOS
7where python     # Windows
8
9# Compare: if these point to different interpreters, that's your problem
10python -c "import sys; print(sys.executable)"

If pip belongs to Python 3.9 but you run Python 3.11, the package went into the wrong site-packages. Using python -m pip prevents this.

Mistakes that put packages in the wrong place

  • Running a bare pip that belongs to a different interpreter than your python. Use python -m pip install.
  • Installing globally on a system where the OS manages its own Python packages (for example Debian/Ubuntu). This can break OS tools. Use a virtual environment or --user instead.
  • Assuming pip list shows what your current interpreter can import. With several Python installations, it only lists packages for the interpreter it is tied to. Use python -m pip list.
  • Using --user inside a virtual environment. Inside a venv, plain pip install is all you need.
  • Forgetting that scripts (bin/) live in a different directory from the Python modules in site-packages. A successful import does not mean the CLI tool is on your PATH.

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms