pip Cheat Sheet

Table of contents

  1. ๐Ÿ”น What is pip?
  2. ๐Ÿ”น pip Command Structure
    1. Example:
  3. ๐Ÿ”น Core pip Commands Overview
  4. ๐Ÿ”น pip Install Syntax
    1. Basic Install
    2. Version-Specific
    3. Editable Mode (for local development)
    4. Install from URLs or VCS
  5. ๐Ÿ”น pip Requirements Files
    1. Create
    2. Use
    3. Best Practices
  6. ๐Ÿ”น pip Configuration Management
    1. Configuration Locations
    2. Commands
  7. ๐Ÿ”น pip Caching and Performance
  8. ๐Ÿ”น pip Environment & Permissions
  9. ๐Ÿ”น Common Errors & Fixes
  10. ๐Ÿ”น Best Practices
  11. ๐Ÿ”น Useful Commands at a Glance
  12. ๐Ÿ“Œ Basic pip Commands
  13. ๐Ÿ“ฆ Installing Packages
  14. โŒ Uninstalling Packages
  15. ๐Ÿ” Searching & Showing Packages
  16. ๐Ÿ“ Requirements Files
  17. ๐ŸŒ Using Indexes and Sources
  18. ๐Ÿงช Installing from Other Sources
  19. โš™๏ธ Configuration & Environment
  20. ๐Ÿ”’ Proxy and Trusted Hosts
  21. ๐Ÿ› ๏ธ Common Flags
  22. ๐Ÿ”„ Upgrading pip
  23. ๐Ÿ“ฆ 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

CommandPurpose
installInstall packages
uninstallUninstall packages
listList installed packages
showShow info about a package
freezeOutput packages in requirements.txt format
checkCheck for broken dependencies
downloadDownload packages without installing
wheelBuild wheels from source
search๐Ÿ”ด Deprecated
configManage pip config settings
cacheInspect pipโ€™s cache
debugShow diagnostic info
helpHelp 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)

pip install -e .

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

  • Pin versions for consistency:

    numpy==1.25.0
    pandas==2.2.0
    

๐Ÿ”น pip Configuration Management

Configuration Locations

ScopeLocation
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 Caching and Performance

  • 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

OptionDescription
--userInstall to user site-packages
--rootInstall under custom root
--prefixSpecify installation prefix
--targetInstall to custom directory

Example:

pip install --user requests

๐Ÿ”น Common Errors & Fixes

IssueFix
Permission deniedUse --user or sudo
SSL: CERTIFICATE_VERIFY_FAILEDUse --trusted-host
No module named pipReinstall 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

CommandDescription
pip --versionShow pip version
pip helpDisplay help for pip
pip <command> --helpHelp for a specific command (e.g., pip install --help)

๐Ÿ“ฆ Installing Packages

CommandDescription
pip install <package>Install latest version of a package
pip install <package>==1.2.3Install specific version
pip install '<package>>=1.2,<2.0'Install version range
pip install -r requirements.txtInstall 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

CommandDescription
pip uninstall <package>Uninstall a package
pip uninstall -r requirements.txtUninstall all in file

๐Ÿ” Searching & Showing Packages

CommandDescription
pip search <package>๐Ÿ”ด Deprecated in recent versions
pip show <package>Show details (version, dependencies, location, etc.)
pip listList all installed packages
pip list --outdatedList outdated packages
pip list --uptodateList up-to-date packages
pip checkCheck for broken dependencies

๐Ÿ“ Requirements Files

CommandDescription
pip freezeOutput installed packages in requirements.txt format
pip freeze > requirements.txtSave all installed packages to file
pip install -r requirements.txtInstall all packages from file
pip uninstall -r requirements.txtUninstall all packages in file

๐ŸŒ Using Indexes and Sources

CommandDescription
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

CommandDescription
pip install git+https://github.com/user/repo.gitInstall from a GitHub repo
pip install https://example.com/pkg.whlInstall from a wheel file URL
pip install ./package.whlInstall from a local wheel
pip install <package>.tar.gzInstall from a tarball source distribution

โš™๏ธ Configuration & Environment

CommandDescription
pip config listShow 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

CommandDescription
pip install <package> --proxy http://user:pass@proxy:portInstall using a proxy
pip install <package> --trusted-host <hostname>Bypass SSL verification for a host

๐Ÿ› ๏ธ Common Flags

FlagDescription
--quiet or -qReduce output verbosity
--verbose or -vIncrease output verbosity
--no-cache-dirDonโ€™t use cache
--userInstall to user site directory (not system-wide)
--upgrade-strategy eagerUpgrade all dependencies eagerly

๐Ÿ”„ Upgrading pip

python -m pip install --upgrade pip

๐Ÿ“ฆ Wheel Support

CommandDescription
pip wheel <package>Build a wheel
pip install <package>.whlInstall a wheel file
pip install wheelInstall wheel tool support