How to Install Python Pip / PIP3 on Debian 11 Bullseye

PIP is the standard package manager for installing Python packages. With PIP, you can list, search and download to install packages from the Python Package Index (PyPI). PIP was first included with the Python installer since version 3.4 for Python 3 release and 2.7.9 for Python 2 and is well utilized with many Python projects.

In the following tutorial, you will learn how to install the PIP / PIP2 or PIP3 on Debian 11 Bullseye operating system.

Prerequisites

  • Recommended OS: Debian 11 Bullseye
  • User account: A user account with sudo or root access.
  • Required Packages: Python2 or Python3.

Update Operating System

Update your Debian operating system to make sure all existing packages are up to date:

sudo apt update && sudo apt upgrade -y

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@debian~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on Adding a User to Sudoers on Debian.

To use the root account, use the following command with the root password to log in.

su
Advertisement

PIP2 vs PIP3

For those new to the python programming language altogether, you may wonder what the difference between PIP2 and PIP3 is. To sum it up, PIP2 is a soft link for a particular installer running an older python version. PIP3 is an updated version of pip which is used basically for python 3+.

It is highly recommended to use Python 3 and PIP3, and you should be upgrading to this as soon as possible.

PIP2 OR PIP3 VS APT Package Manager

A question that is asked regularly should I use APT or PIP. This is a choice that every user must make. APT is faster however is more outdated where PIP is used to download and install packages directly from PyPI. For those unaware, PyPI is hosted by Python Software Foundation, a package manager that only deals with python packages that are often more updated than those hosted by Canonical through APT. The only drawback of using PIP through PyPI is that the packages can take longer to install.

Advertisement

Install Python 2 or 3 on Debian 11

Install Python 2

By default, Debian 11 have Python 3 installed. However, for users that require Python 2, this can be installed with either the python or python2 command.

To install Python2, which will use PIP2 later on, use the following command.

sudo apt install python -y

Next, proceed to the Install PIP and install the corresponding version to your Python installation.

Confirm the installation, or if python or python2 is installed, to begin with by checking the version build.

python --version

Example output:

Python 2.7.18

Install Python 3

As stated, Python 3 should be installed by default, and if missing, you can re-install using the following command.

sudo apt install python3 -y

Next, proceed to the Install PIP and install the corresponding version to your Python installation.

Confirm the installation, or if python3 is installed, to begin with by checking the version build.

python3 --version

Example output:

Python 3.9.2

Install PIP 2 or 3 on Debian 11

Install PIP2

To install PIP on Debian 11, you must download the handy script manually as it is not featured in the default repositories anymore.

First, make sure the CURL package is installed.

sudo apt install curl -y

To install PIP2, you will need to download the .py script as follows:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py

Now execute the .py script:

sudo python2 get-pip.py

Example output of dependencies that will be installed:

How to Install Python Pip / PIP 3 on Debian 11 Bullseye

Type Y, then press the enter key to continue the installation.

To confirm if PIP2 was installed successfully, run the following version command:

pip2 --version

Example output:

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

PIP2 and Python 2 should be upgraded to Python 3 and PIP 3 as soon as possible as this has reached the end of life.

Install PIP3

To Install PIP3(For Python 3+):

sudo apt install python3-pip 

Example output of dependencies that will be installed:

How to Install Python Pip / PIP 3 on Debian 11 Bullseye

To confirm if PIP3 was installed successfully, run the following version command:

pip3 --version 

Example output:

pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)

Note, this version number will change over time and is an example only.

Advertisement

How to Use PIP / PIP3

PIP has quite an extensive list of packages that can be installed, an easy way to see some of what is available is to run the PIP command list and search. The commands will work on both PIP and PIP3 with a slight adjustment, of course.

The tutorial will use some examples below for PIP3.

First off, to view a list of all pip commands and options, type the following command:

pip3 --help
How to Install Python Pip / PIP 3 on Debian 11 Bullseye

Example of using pip3 help, example below on getting help on download:

pip3 download --help

Example output:

How to Install Python Pip / PIP 3 on Debian 11 Bullseye

To list packages that are available to install on PIP3, use the following:

pip3 --list

Example output:

How to Install Python Pip / PIP 3 on Debian 11 Bullseye

If you want to narrow down the list, use the search feature as follows:

pip3 search PACKAGE_NAME

To install a package using PIP3, use the following command:

pip3 install numpy

In the above example, the NumPy package was installed.

Example output:

How to Install Python Pip / PIP 3 on Debian 11 Bullseye

To remove a PIP3 package, use the following command:

sudo pip3 uninstall numpy

Example output:

How to Install Python Pip / PIP 3 on Debian 11 Bullseye

Type Y, then press ENTER KEY to complete the uninstallation.

Example output:

Successfully uninstalled numpy-1.21.3

How to Remove (Uninstall) PIP on Debian 11

To remove PIP from your Debian system, follow the below commands depending on which version you have installed.

To remove PIP:

sudo python -m pip uninstall pip

Example output:

How to Install Python Pip / PIP 3 on Debian 11 Bullseye

Type Y, then press ENTER KEY to complete the uninstallation.

Example output:

Successfully uninstalled pip-20.3.4

To remove PIP3:

sudo apt autoremove python3-pip --purge

Example output:

How to Install Python Pip / PIP 3 on Debian 11 Bullseye

Type Y, then press ENTER KEY to complete the uninstallation.

Advertisement

Comments and Conclusion

In the tutorial, you have learned how to install PIP for Python or Python 3 and search, install, and remove packages. To find out further information on PIP, visit the official documentation.

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x