Where does pip install its packages?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
pip installs packages into the site-packages directory of whichever Python interpreter it is associated with. The exact path depends on three things: the operating system, whether you are inside a virtual environment, and whether you used the --user flag. The most reliable way to find the actual path is to ask Python directly with python -m site rather than memorizing OS-specific conventions.
The Core Rule
Every Python interpreter has a site-packages directory where third-party packages are installed. When you run pip install requests, pip places the package files into the site-packages for the Python interpreter that pip belongs to.
The most common source of confusion is running pip tied to one interpreter while running your code with a different interpreter. That is why the recommended invocation is:
This ensures the pip you invoke is the one bundled with the exact python binary you are calling.
Finding the Actual Install Location
Method 1: python -m site
This prints all site-packages directories for the current interpreter:
Output includes sys.path, user site-packages, and global site-packages directories.
Method 2: Scripted Query
For a precise, parseable answer:
Method 3: pip show for a Specific Package
If you want to know where a specific package was installed:
The Location: field in the output tells you the directory. You can also check from within Python:
Install Locations by Context
| Context | Typical Path (Linux/macOS) | Typical Path (Windows) |
| System/global install | /usr/lib/python3.X/site-packages | C:\Python3X\Lib\site-packages |
| Homebrew Python (macOS) | /opt/homebrew/lib/python3.X/site-packages | N/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-packages | C:\Users\you\miniconda3\envs\myenv\Lib\site-packages |
These paths vary by distribution and Python build, so always verify with python -m site rather than hard-coding paths.
Virtual Environments
When a virtual environment is activated, pip installs into that environment's own site-packages, completely isolated from the system Python.
Deactivating the environment reverts python and pip to the system versions. Packages installed inside the venv are not visible outside it, and vice versa.
The --user Flag
When you do not have write access to the global site-packages (common on shared servers or when the system Python is managed by the OS package manager), --user installs to a per-user directory:
The user site-packages path is typically ~/.local/lib/python3.X/site-packages on Linux/macOS. You can query it with:
Note that --user and virtual environments are mutually exclusive. If you are inside a venv, --user is ignored (or raises an error, depending on the pip version).
Packages vs. Scripts: Two Different Locations
When pip installs a package that includes command-line tools (like black, flask, or pytest), it installs two things in two places:
| What | Where | Example |
| Python package | site-packages/black/ | The importable library |
| CLI script | bin/ (Linux/macOS) or Scripts/ (Windows) | The black command you run in the terminal |
This is why you can sometimes import a package successfully but get "command not found" when trying to run its CLI tool. The bin/ or Scripts/ directory may not be on your PATH.
Diagnosing "Module Not Found" After Installation
If pip install succeeds but import fails, you almost certainly have a Python interpreter mismatch. Run this diagnostic:
If pip belongs to Python 3.9 but you are running Python 3.11, the package is installed in the wrong site-packages. Always use python -m pip to avoid this.
Common Pitfalls
- Using a bare
pipcommand that belongs to a different interpreter than thepythonyou are running. Always usepython -m pip installto keep them aligned. - Installing packages globally on a system where the OS manages its own Python packages (e.g., Debian/Ubuntu). This can break OS tools. Use a virtual environment or
--userinstead. - Assuming
pip listshows packages available to your current interpreter. If multiple Python installations exist,pip listonly shows packages for the interpreter it is tied to. Verify withpython -m pip list. - Using
--userinside a virtual environment. The--userflag either gets ignored or raises an error, depending on the pip version. Inside a venv, just usepip installwithout flags. - Forgetting that
site-packagesfor scripts (bin/) is a different directory thansite-packagesfor Python modules. A successful import does not guarantee the CLI tool is on yourPATH.
Summary
pipinstalls into thesite-packagesdirectory of its associated Python interpreter. Usepython -m pipto guarantee the right one.- The exact path depends on the OS, whether you are in a virtual environment, and whether you used
--user. - Use
python -m siteto discover all site-packages directories andpython -m pip show package_nameto find where a specific package was installed. - Virtual environments are the recommended approach for project dependencies because they provide complete isolation.
- CLI scripts and Python packages install to different directories. A successful
importdoes not mean the command-line tool is on yourPATH.
Related reading
- Where does pip install its packages?
- Where is a complete example of logging.config.dictConfig?
- Where is the code for gradient descent?
- Where is the documentation for the values method of Enum?
- Where is the downloaded Keras dataset stored?
- Where is the folder for Installing tensorflow with pip, Mac OSX?
- Where should virtualenvs be created?
- Where to find Python implementation of Chaikin's corner cutting algorithm?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.