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:
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:
From a Python script
For a precise, parseable answer:
pip show for one package
The Location: field gives the directory. You can also check from inside Python:
Typical paths on Windows, macOS and Linux
| 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 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:
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:
On Linux and macOS this is typically ~/.local/lib/python3.X/site-packages. Query it with:
--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:
| 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 |
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.
"Module not found" after a successful install
If pip install succeeds but import fails, you almost certainly have an interpreter mismatch. Check:
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
pipthat belongs to a different interpreter than yourpython. Usepython -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
--userinstead. - Assuming
pip listshows what your current interpreter can import. With several Python installations, it only lists packages for the interpreter it is tied to. Usepython -m pip list. - Using
--userinside a virtual environment. Inside a venv, plainpip installis all you need. - Forgetting that scripts (
bin/) live in a different directory from the Python modules insite-packages. A successful import does not mean the CLI tool is on yourPATH.
Related reading
- 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?
- Where to put BeautifulSoup code in Asyncio Web Scraping Application
System design interview problems on this topic
- Design a Web Crawler: solution and walkthrough
- Design a Task Scheduler: solution and walkthrough
- Design a URL Shortener (TinyURL): solution and walkthrough
- Design an API Rate Limiter: solution and walkthrough
.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 courseNo 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 courseData 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.