Read in 3 minutes

last updated 

How to install Pip on Debian 9

Pip is a package management system that simplifies installation and management of software packages written in Python such as those found in the Python Package Index (PyPI).

This tutorial will walk you through installing Python Pip on Debian 9 and teach you how to install and manage Python packages with pip.

Prerequisites

Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges.

It is worth mentioning that if you want to install a python module globally you should prefer to install it as a package using the apt manager. Use pip to install python modules globally only if there is no package available.

Usually you would use pip inside a virtual environments only. Python Virtual Environment allows you to install Python modules in an isolated location for a specific project, rather than being installed globally. This way you do not have to worry of affecting other Python projects.

In the following sections we will show you how install pip for both Python 2 pip and Python 3 pip3 using the apt package manager.

Install Pip for Python 2

Follow the steps below to install Pip for Python 2 on your Debian system:

  1. Start by updating the packages index:

    sudo apt update
  2. Install pip for Python 2 and all of it’s dependencies:

    sudo apt install python-pip
  3. Once the installation is complete, verify the installation by issuing the following command which will print the pip version:

    pip --version

    The version number may vary, but it will look something like this:

    pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

Install pip for Python 3

Follow the steps below to install Pip for Python 3 on Debian:

  1. First, update the package list with:

    sudo apt update
  2. Next, install pip for Python 3 and all of it’s dependencies by typing:

    sudo apt install python3-pip
  3. Verify the installation by printing the pip version:

    pip3 --version

    The version number may be different, but it will look something like the one below:

    pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)

Pip Usage

In this section we will show you a few useful basic pip commands. With pip we can install packages from PyPI, version control, local projects, and from distribution files but in most cases you will install packages from PyPI.

Let’s say we want to install a package named croniter, we can do that by issuing the following command:

pip install croniter

croniter provides iteration for datetime object with cron like format

To uninstall a package run:

pip uninstall package_name

To search packages from PyPI:

pip search "search_query"

To list installed packages:

pip list

To list outdated packages:

pip list --outdated
Package       Version Latest Type
------------- ------- ------ -----
cryptography  1.7.1   2.2.2  wheel
enum34        1.1.6   1.1.6  wheel
idna          2.2     2.7    wheel
ipaddress     1.0.17  1.0.22 wheel
keyring       10.1    13.0.0 wheel
keyrings.alt  1.3     3.1    wheel
pip           9.0.1   10.0.1 wheel
pyasn1        0.1.9   0.4.3  wheel
pycrypto      2.6.1   2.6.1  sdist
pygobject     3.22.0  3.28.3 sdist
pyxdg         0.25    0.26   wheel
SecretStorage 2.3.1   2.3.1  sdist
setuptools    33.1.1  39.2.0 wheel
six           1.10.0  1.11.0 wheel
wheel         0.29.0  0.31.1 wheel

Conclusion

In this tutorial, we have shown you how to install pip on your Debian system and how to manage Python packages using pip. For more information about pip, check the pip user guide.

If you have any questions or feedback, feel free to comment below.