PIP - Package Installer for Python

PIP is the Package Installer for Python. It is used to install packages from Python Package Index (PyPI) and other indexes.

PyPI - Python Package Index

PyPI is the default repository of Python packages for Python community that includes frameworks, tools and, libraries. Python developers can install and use packages in the Python application. It is open to all Python developers to consume and distribute their distributions. Developers can search or browse projects from pypi.org.

Install pip

PIP has been included with Python installer since Python 3.4. You can verify whether the pip is installed on your machine by running the following command in your console:

C:\>pip --version
pip 18.0 from c:\python37\lib\site-packages\pip (python 3.7)

If you are using an older version of pip, you can upgrade pip by running the following command on Windows:

C:\> python -m pip install -U pip

Execute the following command on Linux or Mac OS to upgrade pip:

$ pip install -U pip

If pip isn't already installed, then first try to bootstrap it from the standard library by executing the following command in your console or terminal window:

python -m ensurepip --default-pip

If that still doesn't install pip, the following steps should install pip on your platform.

  1. Download get-pip.py from https://bootstrap.pypa.io/get-pip.py and save it to your local folder.
  2. Navigate command prompt or terminal to the folder where you have downloaded the file and run the command: python get-pip.py

This command will install pip in your pc. Additionally, it also installs the wheel and setuptools.

pip Help command

The pip help command is used to get a list of all the functions available in pip.

C:\> pip help

pip <command> [options]

install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
check Verify installed packages have compatible dependen cies.
config Manage local and global configuration.
search Search PyPI for packages.
cache Inspect and manage pip's wheel cache.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
debug Show information useful for debugging.
help Show help for commands.

General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring
environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be
used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be
used up to 3 times (corresponding to WARNING,
ERROR, and CRITICAL logging levels).
--log <path > Path to a verbose appending log.
--no-input Disable prompting for input.
--proxy <proxy > Specify a proxy in the form [user:[email protected]]proxy.server:port.
--retries <retries > Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec > Set the socket timeout (default 15 seconds).
--exists-action <action > Default action when a path already exists:
(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
--trusted-host <hostname > Mark this host or host:port pair as trusted,
even though it does not have valid or any HTTPS.
--cert <path > Path to alternate CA bundle.
--client-cert <path > Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
--cache-dir <dir > Store the cache data in <dir >.
--no-cache-dir Disable the cache.
Don't periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with --no-index.
--no-color Suppress colored output
Silence deprecation warnings for upcoming
unsupported Pythons.
--use-feature <feature > Enable new functionality, that may be backward
--use-deprecated <feature > Enable deprecated functionality, that will be
removed in the future.

Installing packages

PyPI maintains packages as projects. Use the following pip command to install the latest version of the project.

Pip install "project-name"

Use the following command installs the specific version of the project:

pip install "project-name==2.4"

Use the following command to install a version that's "compatible" with a certain version:

pip install "project-name~=2.4"

Let's install a package to send an HTTP request in Python. urllib3 is a powerful, user-friendly HTTP client for Python. Before using urllib3 package in your application, install it using the pip command, as shown below.

C:\MyProject> Pip install urllib3

The above command will install the latest version of urllib3. Now, you can import and use it, as shown below.

Example: Use urllib3 Package
import urllib3

http = urllib3.PoolManager()
req = http.request('GET', 'http://www.google.com')

List packages

The list command can be used to see all the packages that have been installed on the system. If you want to check all the packages, use the pip list command:

C:\> pip list

Package Version
------- -------
argon2-cffi 20.1.0
async-generator 1.10
attrs 20.2.0
backcall 0.1.0
bleach 3.2.1
certifi 2020.6.20
cffi 1.14.3
chardet 3.0.4
colorama 0.3.9
decorator 4.3.0
defusedxml 0.6.0
entrypoints 0.3
idna 2.10
importlib-metadata 2.0.0
ipykernel 5.3.4
ipython 6.5.0
ipython-genutils 0.2.0
jedi 0.12.1
Jinja2 2.11.2
json5 0.9.5
jsonschema 3.2.0
jupyter-client 6.1.7
jupyter-core 4.6.3
jupyterlab-pygments 0.1.2
jupyterlab-server 1.2.0
MarkupSafe 1.1.1
mistune 0.8.4
mongobox 0.1.8
nbclient 0.5.0
nbconvert 6.0.7
nbformat 5.0.7
nest-asyncio 1.4.1
notebook 6.1.4
packaging 20.4
pandocfilters 1.4.2
parso 0.3.1
pickleshare 0.7.4
pip 20.2.4
prometheus-client 0.8.0
prompt-toolkit 1.0.15
pycparser 2.20
Pygments 2.7.1
pyparsing 2.4.7
pyrsistent 0.17.3
python-dateutil 2.8.1
pywin32 228
pywinpty 0.5.7
pyzmq 19.0.2
requests 2.24.0
Send2Trash 1.5.0
setuptools 39.0.1
simplegeneric 0.8.1
six 1.11.0
terminado 0.9.1
testpath 0.4.4
tornado 6.0.4
traitlets 4.3.2
urllib3 1.26.2
wcwidth 0.1.7
webencodings 0.5.1
zipp 3.3.0

This will list all the packages available to use in your system. Notice that urllib3 package is also listed there.

Show package

If you want to check the metadata of a package, then use pip show command. The following command will display the metadata of the urllib3 package.

C:\> pip show urllib3

Name: urllib3
Version: 1.26.2
Summary: HTTP library with thread-safe connection pooling, file post, and more.
Home-page: https://urllib3.readthedocs.io
Author: Andrey Petrov
Author-email: [email protected]
License: MIT
Location: c:\python37\lib\site-packages
Required-by: requests

Uninstalling a Package

The pip uninstall command can be used to remove a package. For example, if you want to remove urllib3 package, you can simply use the following command:

$ pip uninstall urllib3

The pip package manager will ask you to confirm if you want to uninstall the package. Proceed (y/n)?: If you press y, the package will be removed.

Thus, you can use pip as a package manager of your Python application.

Want to check how much you know Python?