Twitter
@opensourceway | facebook.com/opensourceway | CC BY-SA 4.0
opensource.com
Get to know the most useful pip commands to help you install, manage, and use Python
software packages.
Opensource.com: pip Cheat Sheet
BY MOSHE ZADKA
Package sources
Install package from PyPI
$ pip install requests
Install package from a local wheel le
$ pip install requests-2.22.0-py2.py3-none-any.whl
Install package from a Git repository
$ pip install git+https://github.com/psf/requests.git
Install package from a directory
$ pip install /home/user/src/requests
search
Search for packages mentioning “term”
pip search <some term>
show
Show details of package
pip show <some package>
It is usually easier to search and view information
using the PyPI.org web site
DownloaD
Download a package and all of its dependencies.
Except in unusual cases, it is better to run “pip wheel”
and have the packages in a wheel format.
pip download <package>
list installeD
Lists all modules currently installed by
pip
. Usually
pip freeze
is a better alternative.
pip list
Freezing (useful for recording an environment so it can be
duplicated later)
Capture all currently installed versions in a text le
$ pip freeze > requirements.txt
Install packages from a requirements le
$ pip install -r requirements.txt
custom inDexes
Install from an alternative index to PyPI
$ pip install --index-url https://our-pypi-proxy.internal.example.com
Install packages using an *extra index* for local, unpublished externally, packages.
$ pip install --extra-index-url https://local-pacakges.internal.example.com
Package versions
Install specic version
$ pip install requests==2.22.0
Install most recent version in a range
$ pip install requests>=2.22.0,<3
Install package, avoid a specic version
$ pip install requests!=2.21.0
wheels
Produce wheels of the package and all its dependencies,
and put them in the “wheelhouse” directory
pip wheel --wheel-dir ./wheelhouse/ some-package[==version]
Produce wheels of all packages named in requirements le,
and put them in the “wheelhouse” directory
pip wheel --wheel-dir wheelhouse -r requirements.txt
terminology
A “distribution” is something that pip can install.
A “package” is something that can be used in
import
statements.
Most distributions include a single package of the same name, but there are exceptions. For example,
pip install attr
s
installs a package importable with
import attr
A “wheel” is a special le with the sufx
.whl
Installing a wheel just copies les into place. No compiling or processing is required.