W3docs

Python PIP

Learn how to use pip to install, upgrade, and remove Python packages, pin versions, export requirements, and avoid common pitfalls.

pip is Python's built-in package manager. It downloads packages from PyPI (the Python Package Index) and installs them so you can import them in your code. If you have Python 3.4 or later, pip is already included — no separate install needed.

This chapter covers everything you need to use pip confidently: checking your installation, installing and removing packages, pinning versions, exporting dependencies, and fixing common errors.

Checking your pip installation

Open a terminal and run:

pip --version

You will see output similar to:

pip 24.0 from /usr/lib/python3/dist-packages/pip (python 3.12)

If the command is not found, or if you have multiple Python versions, use the python -m pip form instead — it guarantees you are running pip for the Python interpreter you intend:

python -m pip --version

Upgrading pip

pip releases new versions frequently. Keep it current to avoid resolver warnings:

python -m pip install --upgrade pip

Installing packages

Basic install

pip install requests

pip downloads requests and all of its dependencies from PyPI and installs them into your active Python environment. After the install you can import the package immediately.

Installing a specific version

Pin to an exact version when reproducibility matters:

pip install requests==2.31.0

You can also express version ranges using comparison operators:

pip install "requests>=2.28,<3.0"

Always quote ranges in the shell to prevent < and > from being interpreted as redirects.

Installing from a requirements file

A requirements.txt file lists all the packages a project needs, one per line. Install every package in the file with a single command:

pip install -r requirements.txt

A typical requirements.txt looks like this:

requests==2.31.0
flask>=3.0,<4.0
sqlalchemy

Installing in editable mode

When you are developing a local package and want changes to take effect without reinstalling, use the -e flag:

pip install -e .

This links the package directory directly into the environment instead of copying files.

Installing for the current user only

If you do not have permission to write to the system Python directory and are not using a virtual environment, add --user:

pip install --user requests

The package is installed into your home directory (~/.local/ on Linux/macOS). This is a fallback — using a virtual environment is almost always the better choice.

Listing and inspecting packages

List all installed packages

pip list

Example output:

Package    Version
---------- -------
pip        24.0
requests   2.31.0
setuptools 69.0.3

Show details about a package

pip show requests

Output includes version, author, license, install location, and — importantly — what it requires and what requires it:

Name: requests
Version: 2.31.0
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
License: Apache 2.0
Location: /usr/lib/python3/dist-packages
Requires: certifi, charset-normalizer, idna, urllib3
Required-by:

Check for version conflicts

pip check

pip scans all installed packages and reports any incompatible requirements. If everything is fine, the command exits silently.

Upgrading and removing packages

Upgrade a package

pip install --upgrade requests

This installs the latest version that satisfies any constraints already present in your environment.

Upgrade all packages (no built-in command)

pip has no single command to upgrade every installed package. A common workaround using pip list and xargs:

pip list --outdated --format=freeze | cut -d = -f 1 | xargs pip install --upgrade

Use this carefully in a project environment — mass upgrades can introduce breaking changes. Pinned requirements.txt files are a safer alternative.

Uninstall a package

pip uninstall requests

pip asks for confirmation before removing the package. Pass -y to skip the prompt in scripts:

pip uninstall -y requests

Exporting dependencies

Freeze the current environment

pip freeze outputs every installed package and its exact version in a format suitable for a requirements.txt file:

pip freeze > requirements.txt

The output looks like:

certifi==2024.2.2
charset-normalizer==3.3.2
idna==3.6
requests==2.31.0
urllib3==2.2.1

Share requirements.txt with teammates or include it in your repository so anyone can reproduce your environment with pip install -r requirements.txt.

pip and virtual environments

By default pip installs packages globally (or per-user with --user). This causes problems when two projects need different versions of the same library.

The solution is a virtual environment: an isolated Python installation that has its own pip and its own site-packages directory. When a virtual environment is active, pip install affects only that environment.

# Create a virtual environment named .venv
python -m venv .venv

# Activate it (macOS / Linux)
source .venv/bin/activate

# Activate it (Windows)
.venv\Scripts\activate

# Now pip works inside the isolated environment
pip install requests

See the Python Virtual Environments chapter for the full workflow.

Getting verbose output

When an installation fails, the default error message can be cryptic. Add --verbose (or -v) to see every step pip takes:

pip install --verbose requests

Add -v twice (-vv) for even more detail, including the HTTP requests pip makes to PyPI.

Common errors and fixes

ErrorLikely causeFix
command not found: pippip not on PATH or not installedUse python -m pip or install pip via ensurepip
Permission deniedNo write access to system PythonAdd --user or activate a virtual environment
Could not find a version that satisfies the requirementPackage name is wrong, or version does not existCheck the exact name on pypi.org
ResolutionImpossibleConflicting version requirements between packagesUse pip check to identify conflicts; relax version pins
SSL certificate verify failedCorporate proxy or outdated certificatesUpdate your CA bundle or use --trusted-host pypi.org

Quick-reference table

TaskCommand
Check pip versionpip --version
Install a packagepip install requests
Install a specific versionpip install requests==2.31.0
Install from requirements filepip install -r requirements.txt
Upgrade a packagepip install --upgrade requests
Uninstall a packagepip uninstall requests
List installed packagespip list
Show package detailspip show requests
Export current environmentpip freeze > requirements.txt
Check for conflictspip check

Practice

Practice
Which pip command exports all installed package versions to a file?
Which pip command exports all installed package versions to a file?
Was this page helpful?