How to install a Python package with pip

Being an open source computer programming language, Python offers the opportunity to everyone out there to contribute their source code to the community, so people can benefit from the software packages of each other.

Based on my personal experience with the Python computer programming language so far, there are many packages out there which one can install to develop their software. And as far as my knowledge goes about the Python computer technology, there are many different ways to install a package in it.

A very practical way which can help the Python coder install packages on their machine, widely used by professional developers, is through pip.

What's the one thing every developer wants? More screens! Enhance your coding experience with an external monitor to increase screen real estate.

What is pip

According to the official Python documentation, pip stands for the utility which helps one to automatically download software from the python package index, known as PyPI. Not only does the pip utility help one to download and install Python packages for their project, but it also helps them to manage their packages and generate dependencies for their software.

For those curious computer geeks who always want to know more, pip is a recursive acronym that can stand for either Pip Install Package or Pip Installs Python.

The following is some information about the pip utility for the Python geeks who are eager to advance their coding skills to the next level.

  • Initial Release: 4 April 2011
  • Repository: Github
  • Language written in: Python
  • Operating System: Independent
  • Platform: Python
  • Official Website: pip.pypa.io

How to install the pip utility on your operating system

Before one can make use of the pip utility, they need to install it on their operating system. According to the official documentation, Python 2.7.9 and later binaries come with pip utility included by default. So the first thing one needs to do before going any further with this tutorial, is to check the version of Python interpreter installed on their machine.

One can easily check their version of Python by running the following command in the console of their operating system.

python –version

The above command produces the following output on my machine.

Python 2.7.12

Since the version of Python which is installed on my machine is greater than 2.7.9, it means that the pip utility is already shipped into my Python binary.

To prove that the pip utility is already installed on my machine, the following command should be run on the console of my unix based operating system.

pip

The result of the above command is shown below.

Usage:
pip [options]

Commands:
install Install packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
search Search PyPI for packages.
wheel Build wheels from your requirements.
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.
–log Path to a verbose appending log.
–proxy Specify a proxy in the form
[user:passwd@]proxy.server:port.
–retries Maximum number of retries each connection should
attempt (default 5 times).
–timeout Set the socket timeout (default 15 seconds).
–exists-action Default action when a path already exists:
(s)witch, (i)gnore, (w)ipe, (b)ackup.
–trusted-host Mark this host as trusted, even though it does
not have valid or any HTTPS.
–cert Path to alternate CA bundle.
–client-cert Path to SSL client certificate, a single file
containing the private key and the certificate
in PEM format.
–cache-dir Store the cache data in .
–no-cache-dir Disable the cache.
–disable-pip-version-check
Don’t periodically check PyPI to determine
whether a new version of pip is available for
download. Implied with –no-index.

The above output is the manual which helps the Python coder to learn about the pip utility, with the main purpose of helping them to find the right instructions for accomplishing their tasks related to managing packages in the Python computer programming language.

Those who have an older version of Python than 2.7.9 can easily install the Python pip utility by downloading the official script from the website and running it with the required privileges on their machine.

Taking in consideration that the reader of this article is in the beginning phase of their coding journey with the Python computer programming language, I will share the proper instructions in a very clear way so anyone can easily setup the pip utility on their operating system.

The first thing we need to do is to get the script which can install pip. Make sure to download it through the link shown below.

https://bootstrap.pypa.io/get-pip.py

Once you have downloaded the script from the official website, make sure to run it with the command which is being shown below.

python get-pip.py

The above script will take care of everything. If it is executed properly you will be able to get the Python pip utility installed on your own machine.

Those who have pip already on their machine, by running the script, their older version will get automatically uninstalled for the new one to be placed.

How to install your first package with pip

Once you have managed to get the Python pip utility on your own machine, the command for the installation of a package is shown below.

pip install name_of_python_package_here

Since I want to install the django web development framework on my machine, I have to use the Python pip utility like shown below.

pip install django

Once the above command is being run on my machine, I get the following.

Once the Python package is being installed through pip, one can easily get information about it by using the command shown below.

pip show django

In the above case, django is the name of package which I just installed on my machine. After the execution of the above command, the information about the package gets displayed on the console.

Name: Django
Version: 1.11.13
Summary: A high-level Python Web framework that encourages rapid development and clean, pragmatic design.
Home-page: https://www.djangoproject.com/
Author: Django Software Foundation
Author-email: foundation@djangoproject.com
License: BSD
Location: /usr/local/lib/python2.7/site-packages
Requires: pytz
Required-by:

Not only can the Python coder download and install a Python package automatically through pip, but they can also specify the version of the package they want to get on their machine. With the main purpose of illustrating that, I am going to run the command shown below on my operating system, a command which tries to download and install the latest official version of the Django web framework.

pip install django==2.0.5

Because the version of Python installed on my machine does not support the latest version of the django package, I get the following errors displayed on my console.

Collecting django==2.0.5
Could not find a version that satisfies the requirement django==2.0.5 (from versions: 1.1.3, 1.1.4, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 1.2.7, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.4, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.4.12, 1.4.13, 1.4.14, 1.4.15, 1.4.16, 1.4.17, 1.4.18, 1.4.19, 1.4.20, 1.4.21, 1.4.22, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.5.10, 1.5.11, 1.5.12, 1.6, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9, 1.6.10, 1.6.11, 1.7, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9, 1.7.10, 1.7.11, 1.8a1, 1.8b1, 1.8b2, 1.8rc1, 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.10, 1.8.11, 1.8.12, 1.8.13, 1.8.14, 1.8.15, 1.8.16, 1.8.17, 1.8.18, 1.8.19, 1.9a1, 1.9b1, 1.9rc1, 1.9rc2, 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.9.5, 1.9.6, 1.9.7, 1.9.8, 1.9.9, 1.9.10, 1.9.11, 1.9.12, 1.9.13, 1.10a1, 1.10b1, 1.10rc1, 1.10, 1.10.1, 1.10.2, 1.10.3, 1.10.4, 1.10.5, 1.10.6, 1.10.7, 1.10.8, 1.11a1, 1.11b1, 1.11rc1, 1.11, 1.11.1, 1.11.2, 1.11.3, 1.11.4, 1.11.5, 1.11.6, 1.11.7, 1.11.8, 1.11.9, 1.11.10, 1.11.11, 1.11.12, 1.11.13)
No matching distribution found for django==2.0.5

The idea is that for one to download and install a specific version of a Python package through pip on their machine, they have to follow the syntax shown in the above command.

A very useful command when it comes to the pip utility, is the one shown below.

pip list

When it is executed, the above command gives the information to the Python coder about the packages installed on their machine.

Having the above command executed on my console, I got the following output.

Package Version
———- ——-
Django 1.11.13
et-xmlfile 1.0.1
funcsigs 1.0.2
jdcal 1.3
mock 2.0.0
openpyxl 2.4.1
pbr 2.0.0
pip 10.0.1
pytube 6.2.2
pytz 2018.4
setuptools 23.1.0
six 1.10.0
vboxapi 1.0
virtualenv 15.0.3
wheel 0.29.0

Final thoughts

The pip utility is an advanced tool which can help the Python coder to install packages on their machine so they can use them in their projects. The purpose of this tutorial is to teach the Python beginner how they can download and install a package automatically by using a utility like pip.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Leave a Reply

Your email address will not be published. Required fields are marked *

*