pip cheat sheet: useful Python package commands
A quick reference for installing, inspecting, and managing Python packages. Using python -m pip ensures that pip runs with the selected Python interpreter.
Table of contents
Package installation and management
python -m pip install <package-name>
Installs the specified package.
python -m pip install <package-name>
python -m pip install <package-name>==<version>
Installs a specific version of the package.
python -m pip install <package-name>==<version>
python -m pip install -r requirements.txt
Installs packages from a requirements.txt file.
python -m pip install -r requirements.txt
python -m pip install --upgrade <package-name>
or python -m pip install -U <package-name>
Upgrades the specified package.
python -m pip install --upgrade <package-name>
python -m pip install <package-name>==<version>
Installs the specified version, replacing the installed version if necessary.
python -m pip install <package-name>==<version>
python -m pip install --upgrade -r requirements.txt
Upgrades packages as far as the version specifiers in requirements.txt permit. The file itself is not changed.
python -m pip install --upgrade -r requirements.txt
python -m pip uninstall <package-name>
Uninstalls the specified package.
python -m pip uninstall <package-name>
Package information
python -m pip show <package-name>
Displays information about the specified package.
python -m pip show <package-name>
python -m pip list
Lists all installed packages.
python -m pip list
python -m pip list --outdated
or python -m pip list -o
Shows outdated packages.
python -m pip list --outdated
Package search
Search on PyPI
The pip search command no longer works because PyPI has disabled its XML-RPC search API. Search for packages on pypi.org instead.
Virtual environments
pipenv install
Creates a virtual environment and installs packages from the Pipfile.
pipenv install
pipenv install <package-name>
Installs a package in the virtual environment.
pipenv install <package-name>
pipenv uninstall <package-name>
Uninstalls a package from the virtual environment.
pipenv uninstall <package-name>
pipenv shell
Activates the virtual environment.
pipenv shell
pipenv lock
Generates a Pipfile.lock file with exact package versions.
pipenv lock
Package updates
python -m pip list --outdated
or python -m pip list -o
Lists outdated packages.
python -m pip list --outdated
python -m pip check
Checks whether installed packages have compatible dependencies. It does not scan packages for security vulnerabilities.
python -m pip check
python -m pip install --upgrade pip
Upgrades the pip installation itself.
python -m pip install --upgrade pip
Package files and sources
python -m pip download <package-name>
Downloads the package without installing it.
python -m pip download <package-name>
python -m pip wheel <package-or-path>
Builds wheel archives for a package, requirement, or local project.
python -m pip wheel <package-or-path>
python -m pip install <file-path>
Installs a package from a local file.
python -m pip install <file-path>
python -m pip install <URL>
Installs a package from a URL.
python -m pip install <URL>
Package dependencies
python -m pip check
Checks for missing or incompatible dependencies.
python -m pip check
pipdeptree
Shows the dependency tree of installed packages. pipdeptree is a separate tool and may need to be installed first.
pipdeptree
python -m pip install --no-deps <package-name>
Installs the package without its dependencies.
python -m pip install --no-deps <package-name>
Package management
python -m pip freeze
Prints installed packages in requirements format. Redirect the output to create a snapshot of the current environment.
python -m pip freeze > requirements.txt
pipenv
Manages project dependencies and a virtual environment using Pipfile and Pipfile.lock. Pipenv is a separate tool and may need to be installed first.
pipenv --help
pip configuration
python -m pip config list
Lists active pip configuration values. Use python -m pip config --help to see commands for reading and changing configuration files.
python -m pip config list