Python
pip
package management
installation directory
software development

Where does pip install its packages?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

When using Python, the `pip` tool is an essential element of package management. It simplifies the process of installing and managing packages from the Python Package Index (PyPI). However, a common question that arises among developers, especially those new to Python, is: Where does `pip` install its packages?

Understanding where `pip` installs packages on your system is crucial, as it affects how you import these packages into your Python environment, and it helps in troubleshooting issues related to package accessibility. In this article, we delve into the specifics of `pip` installations, exploring how various environments impact the installation path, and how you can customize these paths when needed.

Default Installation Path

By default, `pip` installs packages in a location that is specific to the Python interpreter it's associated with. The default installation path depends on several factors including the operating system, whether a virtual environment is involved, and the user permissions.

System-wide Installation

When you install a package system-wide using `pip`, the package is typically installed in the site's packages directory of the Python interpreter. Here's how it varies by operating system:

  • Linux/macOS: Packages are generally installed in `/usr/local/lib/pythonX.Y/site-packages/`.
  • Windows: Packages are usually found in `C:\PythonXX\Lib\site-packages`.

For example, if Python 3.9 is installed, packages are often located in `/usr/local/lib/python3.9/site-packages/` on Linux or macOS, or `C:\Python39\Lib\site-packages` on Windows.

Virtual Environments

When a virtual environment is activated, `pip` installs packages in that environment, isolating them from the system's global Python installation.

  • The packages are located in `myenv/lib/pythonX.Y/site-packages/` on Linux and macOS.
  • On Windows, they reside in `myenv\Lib\site-packages`.

This isolation ensures that project dependencies do not interfere with each other or with the system Python environment.

User-specific Installation

`pip` can install packages in a user-specific directory if you use the `--user` flag. This is useful in situations where you don't have permission to install packages system-wide.

  • On Linux and macOS, the path is typically `$HOME/.local/lib/pythonX.Y/site-packages/`.
  • On Windows, it is usually `%APPDATA%\Python\PythonXX\site-packages`.

The user-specific installations ensure that each user on a system can manage their own set of packages without admin privileges.

Customizing Installation Paths

Sometimes, you may want or need to customize where `pip` installs packages. This can be done using environment variables or `pip` configuration files.

Environment Variables

  • PYTHONUSERBASE: This variable alters the user base directory where `pip` installs packages using the `--user` option.
  • VIRTUAL_ENV: When set, `pip` uses it to determine the base of the virtual environment.
  • PYTHONPATH: This affects where Python looks for modules, potentially influencing where `pip` installs packages.

Configuration Files

`pip` can also be configured using configuration files which can specify the `install` directory option:

  1. Global configuration: `/etc/pip.conf` (system-wide)
  2. User-specific configuration: `~/.pip/pip.conf` or `$APPDATA\pip\pip.ini` (Windows)

These files can include options for default directories like:


Course illustration
Course illustration

All Rights Reserved.