Pip — The complete reference guide

A one stop shop for all the pip commands

Dinesh Kumar K B
Nerd For Tech
5 min readMar 17, 2021

--

Photo by Jaredd Craig on Unsplash

Note: For non-members, this article is also available at https://dineshkumarkb.com/tech/pip-the-complete-reference-guide/

Introduction:

pip is the package manager for python.pip can be used to install python libraries from PyPI. In other words, pip is the npm of python. We use pip to install and manage python libraries that are not part of the python standard library.

Motivation:

Any python developer predeminantly uses pip day in and out.However, the usage is limited to just install and occasionally upgrade.

This article is a consolidated non-exhaustive list of all the pip commands every python developer should know. This could be a reference for any future pip commands.

Commands:

Install — plain install:

The install command is used to install the specified library from the pypi package. I am not giving the output of pip commands here as they are well known.

Install — per-user:

This may come in handy in the following scenarios

  • You are not using a virtual environment
  • You are using a shared PC
  • You don’t have admin previleges to install your packages at system level

pip packages are installed to the system directories by default.In case of linux it is(/usr/local/lib/python3.8/dist-packages). When installed with--user flag, it is installed for a specific user.

Here is the code snippet to get sitepackages and usersitepackages.

Install — with proxy:

If your system is located behind a proxy and you are unable to download from PyPI directly, you could use a proxy provided by your organization.

Install — upgrade:

This command upgrades the existing pip library.

Install — from a different host:

Install from a different host apart from PyPI package.

Install — from requirements.txt:

Install from requirements.txt file.

Install — editable mode:

Install a local package in editable mode. This is useful if you have a local package and you would like to use it. The local package is still under development and any changes to the package will reflect.

Install —to a target location:

Install package to a specific location

Installs matplotlib to the current directory. This could be useful if you are uploading your project to AWS Lambda.

Install — from a local directory:

Install from a local directory and do not scan PyPI.

Here, the find links points to current directory as it has the wheel file for certifi library.The--no-index flag specifies not to look in the PyPI package.

Install — from VCS:

The libraries can be installed directly from a version control system like git.This is useful for huge organizations who have their projects as dependencies. If the access to the repository is restricted, this can be installed directly from git.

Uninstall

To uninstall a library..

Version:

Check pip version

Show:

Get information about an installed package. This includes the version, the location where the package is installed and its dependencies.

Freeze:

Predominantly used as an input to requirements.txt file.

This could be very helpful if you are using a virtualenv and want to copy all your dependencies to requirements.txt.

List:

Lists all the installed packages. If executed inside a virtualenv, it will list all the packages installed in the virtual env.

Download:

Download the python libraries but don’t install them

The download command downloads the specified library’s wheel files in addition to their dependecies. The above command should give the following output.By default, the files are downloaded to the current directory.

Search:

pip search searches for python packages. The default location it searches is the PyPI package (https://pypi.org/pypi).

This does not work now.

However, this could be useful if you have libraries hosted internally in your organization like artifcatory.

The default URL could be overridden by the -i flag.

Check:

Checks compatibility for installed packages

Cache:

pip usually stores all the libraries installed in cache.

The wheel files are cached inside dirdirectory. Whenever a pip install is triggered, it checks the local cache and then connects to PyPI.

The idea behind the pip cache is simple ,when you install a Python package using pip for the first time ,it gets saved on the cache .If you try to download/install the same version of the package on a second time ,pip will just use the local cached copy

Please note that this will not work in a virtual environment as there may not be a need to cache libraries .

Disable cache :

Install package without saving to cache.

Help:

Displays help for pip commands.

Verbose:

Run pip in verbose mode for additional information.

This produces a bunch of output with overwhelming information.

Disable pip version check:

Disables the periodic check to PyPI if a new version of pip is available.

I would recommend not disabling this as you may miss important updates from PyPI.

I shall keep adding more commands as and when I happen to use them.

Thanks for reading.

References:

--

--