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 --versionYou 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 --versionUpgrading pip
pip releases new versions frequently. Keep it current to avoid resolver warnings:
python -m pip install --upgrade pipInstalling packages
Basic install
pip install requestspip 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.0You 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.txtA typical requirements.txt looks like this:
requests==2.31.0
flask>=3.0,<4.0
sqlalchemyInstalling 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 requestsThe 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 listExample output:
Package Version
---------- -------
pip 24.0
requests 2.31.0
setuptools 69.0.3Show details about a package
pip show requestsOutput 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 checkpip 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 requestsThis 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 --upgradeUse 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 requestspip asks for confirmation before removing the package. Pass -y to skip the prompt in scripts:
pip uninstall -y requestsExporting 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.txtThe output looks like:
certifi==2024.2.2
charset-normalizer==3.3.2
idna==3.6
requests==2.31.0
urllib3==2.2.1Share 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 requestsSee 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 requestsAdd -v twice (-vv) for even more detail, including the HTTP requests pip makes to PyPI.
Common errors and fixes
| Error | Likely cause | Fix |
|---|---|---|
command not found: pip | pip not on PATH or not installed | Use python -m pip or install pip via ensurepip |
Permission denied | No write access to system Python | Add --user or activate a virtual environment |
Could not find a version that satisfies the requirement | Package name is wrong, or version does not exist | Check the exact name on pypi.org |
ResolutionImpossible | Conflicting version requirements between packages | Use pip check to identify conflicts; relax version pins |
SSL certificate verify failed | Corporate proxy or outdated certificates | Update your CA bundle or use --trusted-host pypi.org |
Quick-reference table
| Task | Command |
|---|---|
| Check pip version | pip --version |
| Install a package | pip install requests |
| Install a specific version | pip install requests==2.31.0 |
| Install from requirements file | pip install -r requirements.txt |
| Upgrade a package | pip install --upgrade requests |
| Uninstall a package | pip uninstall requests |
| List installed packages | pip list |
| Show package details | pip show requests |
| Export current environment | pip freeze > requirements.txt |
| Check for conflicts | pip check |
Related chapters
- Python Modules — understand how Python imports code before you install third-party packages
- Python Virtual Environments — isolate project dependencies so pip installs never conflict