How to find your Python site-packages directory location
Codemia Knowledge Hub ·
Run python -m site or python -c "import site; print(site.getsitepackages())". The site-packages directory is where pip installs third-party packages for one specific Python interpreter, and its location depends on the operating system, the Python version, and whether you use a virtual environment, Conda or the system interpreter.
site-packages is not a machine-wide directory. It belongs to one interpreter installation, so if you query the wrong interpreter you get the wrong path even though the commands are correct.
Step 1: Confirm which interpreter is active
Check which Python you are actually running before asking for package paths. Getting this wrong is the most common cause of "I installed it but Python can't find it".
If you use a virtual environment, activate it first:
On Windows:
The executable path tells you exactly which interpreter the following commands will query.
Step 2: Ask the site module
The built-in site module is the authoritative source for package directories:
Typical output on macOS with a virtual environment:
From the command line
This prints sys.path, the user site-packages location and whether user site is enabled, which is the quickest complete picture.
For just the site-packages path:
Step 3: Use sysconfig for more detail
The sysconfig module gives finer-grained paths:
Output includes:
The key entries:
| Path Name | Meaning |
purelib | Where pure Python packages are installed |
platlib | Where platform-specific (C extension) packages are installed |
scripts | Where executable scripts (entry points) are placed |
include | Where C header files for package development are stored |
purelib and platlib usually point to the same directory. Some Unix installations put architecture-specific packages in a separate location.
Finding where pip installed a package
pip show reports where a specific package lives:
Output:
The Location field is the site-packages directory, which confirms the package went into the environment you expected.
To list every package with its location:
The verbose flag adds a Location column, which reveals packages split across directories (user site vs environment site).
Why python -m pip instead of pip
python -m pip always runs pip under the same interpreter as python. A bare pip can resolve to a different Python installation, especially when several versions are installed:
Typical paths by platform
Do not hardcode these, but recognizing the patterns helps when debugging:
| Platform | Virtual Environment | System Python |
| Linux | .venv/lib/python3.X/site-packages | /usr/lib/python3.X/site-packages |
| macOS | .venv/lib/python3.X/site-packages | /Library/Frameworks/Python.framework/.../site-packages |
| macOS (Homebrew) | .venv/lib/python3.X/site-packages | /opt/homebrew/lib/python3.X/site-packages |
| Windows | .venv\Lib\site-packages | C:\PythonXX\Lib\site-packages |
| Conda | envs/myenv/lib/python3.X/site-packages | lib/python3.X/site-packages (base env) |
3.X follows your Python version. Upgrading Python (for example from 3.11 to 3.12) changes the site-packages directory too, which is why virtual environments are recreated after upgrades.
Checking paths inside notebooks and IDEs
Many import problems come from the terminal using one interpreter while a Jupyter notebook or IDE uses another. Check inside the environment where the problem happens:
If the notebook's interpreter is not the one you expected, fix the Jupyter kernel or IDE configuration rather than reinstalling packages.
Registering a virtual environment as a Jupyter kernel
Then select the "Python (myproject)" kernel in Jupyter to use that environment's packages.
An environment diagnostic script
For teams that often debug environment issues, a small script saves a lot of time:
Run it in each context (terminal, notebook, Docker container, CI job) to see at once whether the environments match.
Virtual environment vs user site vs system site
Packages can be installed in three places:
| Location | Command | Typical Use |
| Virtual environment site-packages | pip install pkg (inside venv) | Project-specific dependencies |
| User site-packages | pip install --user pkg | Per-user packages without sudo |
| System site-packages | sudo pip install pkg | System-wide (generally discouraged) |
Python searches these in order when resolving imports, so a package in the virtual environment shadows the same package in user or system site-packages.
Mistakes that give you the wrong path
- Mixing interpreters. Querying
pipfrom one interpreter and running code with another is the top cause of "package not found". Tie the query to the interpreter withpython -m pip. - Assuming one machine-wide directory. Virtual environments, user installs and Conda environments mean one machine can have dozens of independent
site-packagesdirectories. - Hardcoding guessed paths. A path like
/usr/lib/python3/site-packagesbreaks when the Python version, the OS or the environment layout changes. Query it programmatically. - Forgetting to activate the virtual environment. You get the system Python's site-packages instead of the project's.
sys.prefix != sys.base_prefixtells you whether a virtual environment is active. - Using
sudo pip install. Installing into the system Python can break OS tools that depend on specific package versions. Use virtual environments for projects and--userfor personal tools.
Related reading
- How do I find the location of Python module sources?
- How do I find the time difference between two datetime objects in python?
- How do I find Wally with Python?
- How do I find which attributes my tree splits on, when using scikit-learn?
- How do I fix 'ImportError cannot import name IncompleteRead'?
- How do I format a date in Jinja2?
- How do I format a string using a dictionary in python-3.x?
- How do I forward-declare a function to avoid NameErrors for functions defined later?
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.