pip Cheat Sheet
Table of contents
- ๐น What is pip?
- ๐น pip Command Structure
- Example:
- ๐น Core pip Commands Overview
- ๐น pip Install Syntax
- Basic Install
- Version-Specific
- Editable Mode (for local development)
- Install from URLs or VCS
- ๐น pip Requirements Files
- Create
- Use
- Best Practices
- ๐น pip Configuration Management
- Configuration Locations
- Commands
- ๐น pip Caching and Performance
- ๐น pip Environment & Permissions
- ๐น Common Errors & Fixes
- ๐น Best Practices
- ๐น Useful Commands at a Glance
- ๐ Basic pip Commands
- ๐ฆ Installing Packages
- โ Uninstalling Packages
- ๐ Searching & Showing Packages
- ๐ Requirements Files
- ๐ Using Indexes and Sources
- ๐งช Installing from Other Sources
- โ๏ธ Configuration & Environment
- ๐ Proxy and Trusted Hosts
- ๐ ๏ธ Common Flags
- ๐ Upgrading pip
- ๐ฆ Wheel Support
๐น What is pip?
pip is the Python package installer, used to install and manage packages from PyPI and other indexes.
๐น pip Command Structure
pip [global-options] <command> [command-options] [arguments]
Example:
pip install --upgrade numpy
๐น Core pip Commands Overview
| Command | Purpose |
|---|
install | Install packages |
uninstall | Uninstall packages |
list | List installed packages |
show | Show info about a package |
freeze | Output packages in requirements.txt format |
check | Check for broken dependencies |
download | Download packages without installing |
wheel | Build wheels from source |
search | ๐ด Deprecated |
config | Manage pip config settings |
cache | Inspect pipโs cache |
debug | Show diagnostic info |
help | Help with pip or a command |
๐น pip Install Syntax
Basic Install
pip install <package-name>
Version-Specific
pip install <package-name>==1.0.4
pip install <package-name>~=1.4.2
pip install '<package-name>>=1.2,<2.0'
Editable Mode (for local development)
Install from URLs or VCS
pip install git+https://github.com/user/repo.git
pip install https://example.com/packages/package.whl
๐น pip Requirements Files
Create
pip freeze > requirements.txt
Use
pip install -r requirements.txt
Best Practices
๐น pip Configuration Management
Configuration Locations
| Scope | Location |
|---|
| Global | /etc/pip/pip.conf (Unix) or %PROGRAMDATA%\pip\pip.ini (Windows) |
| User | ~/.pip/pip.conf (Unix) or %APPDATA%\pip\pip.ini (Windows) |
| Virtualenv | <venv>/pip.conf |
Commands
pip config list
pip config get global.index-url
pip config set global.index-url https://pypi.org/simple
pip config unset global.index-url
- pip uses a cache directory (typically
~/.cache/pip) to avoid re-downloading packages. - Use
--no-cache-dir to avoid using the cache.
pip install <package> --no-cache-dir
๐น pip Environment & Permissions
| Option | Description |
|---|
--user | Install to user site-packages |
--root | Install under custom root |
--prefix | Specify installation prefix |
--target | Install to custom directory |
Example:
pip install --user requests
๐น Common Errors & Fixes
| Issue | Fix |
|---|
Permission denied | Use --user or sudo |
SSL: CERTIFICATE_VERIFY_FAILED | Use --trusted-host |
No module named pip | Reinstall via get-pip.py or ensure pip is in PATH |
๐น Best Practices
โ
Always use a virtual environment (e.g., venv, virtualenv)
โ
Pin versions in requirements.txt
โ
Use pip install --upgrade pip regularly
โ
Use pip list --outdated to monitor updates
โ
Avoid using pip and conda together in the same environment (unless you know what youโre doing)
๐น Useful Commands at a Glance
# Create virtual environment
python -m venv env
source env/bin/activate # or .\env\Scripts\activate (Windows)
# Install a package
pip install requests
# Save dependencies
pip freeze > requirements.txt
# Install from file
pip install -r requirements.txt
# Check for outdated packages
pip list --outdated
# Upgrade pip itself
python -m pip install --upgrade pip
๐ Basic pip Commands
| Command | Description |
|---|
pip --version | Show pip version |
pip help | Display help for pip |
pip <command> --help | Help for a specific command (e.g., pip install --help) |
๐ฆ Installing Packages
| Command | Description |
|---|
pip install <package> | Install latest version of a package |
pip install <package>==1.2.3 | Install specific version |
pip install '<package>>=1.2,<2.0' | Install version range |
pip install -r requirements.txt | Install all from a requirements file |
pip install . | Install a local package (from current directory) |
pip install -e . | Install in โeditableโ mode (useful for development) |
pip install --upgrade <package> | Upgrade to latest version |
pip install --pre <package> | Include pre-release versions |
โ Uninstalling Packages
| Command | Description |
|---|
pip uninstall <package> | Uninstall a package |
pip uninstall -r requirements.txt | Uninstall all in file |
๐ Searching & Showing Packages
| Command | Description |
|---|
pip search <package> | ๐ด Deprecated in recent versions |
pip show <package> | Show details (version, dependencies, location, etc.) |
pip list | List all installed packages |
pip list --outdated | List outdated packages |
pip list --uptodate | List up-to-date packages |
pip check | Check for broken dependencies |
๐ Requirements Files
| Command | Description |
|---|
pip freeze | Output installed packages in requirements.txt format |
pip freeze > requirements.txt | Save all installed packages to file |
pip install -r requirements.txt | Install all packages from file |
pip uninstall -r requirements.txt | Uninstall all packages in file |
๐ Using Indexes and Sources
| Command | Description |
|---|
pip install <package> -i <index_url> | Use a custom package index |
pip install <package> --extra-index-url <url> | Add an extra index (e.g. private PyPI) |
pip install <package> --no-index --find-links <dir_or_url> | Install from a local directory or URL without using PyPI |
๐งช Installing from Other Sources
| Command | Description |
|---|
pip install git+https://github.com/user/repo.git | Install from a GitHub repo |
pip install https://example.com/pkg.whl | Install from a wheel file URL |
pip install ./package.whl | Install from a local wheel |
pip install <package>.tar.gz | Install from a tarball source distribution |
โ๏ธ Configuration & Environment
| Command | Description |
|---|
pip config list | Show current config |
pip config get <key> | Get a config value |
pip config set <key> <value> | Set config (e.g. proxy, index-url) |
pip config unset <key> | Remove a config setting |
๐ Config scopes:
--global: System-wide--user: Per-user--site: Per-virtualenv
๐ Proxy and Trusted Hosts
| Command | Description |
|---|
pip install <package> --proxy http://user:pass@proxy:port | Install using a proxy |
pip install <package> --trusted-host <hostname> | Bypass SSL verification for a host |
๐ ๏ธ Common Flags
| Flag | Description |
|---|
--quiet or -q | Reduce output verbosity |
--verbose or -v | Increase output verbosity |
--no-cache-dir | Donโt use cache |
--user | Install to user site directory (not system-wide) |
--upgrade-strategy eager | Upgrade all dependencies eagerly |
๐ Upgrading pip
python -m pip install --upgrade pip
๐ฆ Wheel Support
| Command | Description |
|---|
pip wheel <package> | Build a wheel |
pip install <package>.whl | Install a wheel file |
pip install wheel | Install wheel tool support |