pip Cheatsheet
Quick reference for pip commands covering package installation, version constraints, requirements files, upgrades, virtual environments, and configuration.
pip is the package installer for Python. This cheatsheet covers common pip commands for installing and removing packages, pinning versions, working with requirements files, inspecting installed packages, managing virtual environments, and configuring pip.
Install Packages
Add packages from PyPI and other sources.
| Command | Description |
|---|---|
pip install package | Install the latest version |
pip install pkg1 pkg2 | Install several packages |
pip install --user package | Install into the user site |
pip install -e . | Install local project in editable mode |
pip install 'package[extra]' | Install with optional extras |
pip install ./dist/pkg.whl | Install from a wheel file |
python -m pip install package | Install through the python launcher |
Versions and Sources
Pin versions and install from other indexes.
| Command | Description |
|---|---|
pip install package==1.2.3 | Install an exact version |
pip install 'package>=1.0,<2.0' | Install within a version range |
pip install --upgrade package | Upgrade to the latest version |
pip install --pre package | Allow pre-release versions |
pip install 'git+https://host/repo.git' | Install from a Git repository |
pip install -i https://mirror/simple package | Use an alternate index URL |
pip index versions package | List available versions |
Requirements Files
Record and reproduce a project environment.
| Command | Description |
|---|---|
pip install -r requirements.txt | Install from a requirements file |
pip freeze | Print installed packages with versions |
pip freeze > requirements.txt | Write current packages to a file |
pip download -r requirements.txt -d ./pkgs | Download packages without installing |
pip install --no-deps -r requirements.txt | Install without dependencies |
pip uninstall -r requirements.txt | Remove packages listed in a file |
Remove Packages
Uninstall packages and verify the tree.
| Command | Description |
|---|---|
pip uninstall package | Remove a package |
pip uninstall -y package | Remove without confirmation |
pip uninstall pkg1 pkg2 | Remove several packages |
pip check | Verify installed dependencies |
Inspect Packages
List installed packages and read metadata.
| Command | Description |
|---|---|
pip list | List installed packages |
pip list --outdated | Show packages with newer versions |
pip list --not-required | List packages no other package needs |
pip show package | Show package details |
pip show -f package | List files installed by a package |
pip --version | Show the pip and Python version |
Virtual Environments
Isolate project dependencies with venv.
| Command | Description |
|---|---|
python -m venv myenv | Create a virtual environment |
source myenv/bin/activate | Activate the environment (Linux/macOS) |
deactivate | Leave the active environment |
pip install --upgrade pip | Upgrade pip inside the environment |
pip install --break-system-packages package | Override PEP 668 (use sparingly) |
Configuration and Cache
Adjust pip settings and manage the cache.
| Command | Description |
|---|---|
pip config list | Show the current configuration |
pip config set global.index-url URL | Set a default index URL |
pip install --no-cache-dir package | Install without using the cache |
pip cache dir | Show the cache location |
pip cache info | Show cache size and counts |
pip cache purge | Clear the wheel cache |
Related Guides
Use these references for pip and Python workflows.
| Guide | Description |
|---|---|
Install pip on Debian | Install pip3 on Debian 11, 12, and 13 |
Install pip on Ubuntu | Install pip3 on Ubuntu |
Python Virtual Environments | Create and use isolated environments |
pip vs apt | When to use pip or the system package manager |