Oct 16, 2023 5 min read

How to Install Python pip3 or pip2 on Debian 11

Install Python pip3 or pip2 on Debian 11 with our step-by-step tutorial. The pip is the standard Python package manager.

Install Python pip3 or pip2 on Debian 11
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install Python pip3 or pip2 on Debian 11, let's briefly understand – What is pip?

A pip is the standard Python package manager. It allows you to list, search, and download packages from the Python Package Index (PyPI) for installation. A pipx has been extensively used with numerous Python projects since it was first included with the Python installation in version 3.4 for Python 3 and 2.7.9 for Python 2.

pip2 vs pip3

For those unfamiliar with the Python programming language, you may be wondering what the difference between pip2 and pip3 is. The pip3 is a newer version of pip that is mostly used with Python 3+, whereas pip2 is a soft link for a specific installer running an older Python version.

Using Python 3 and pip3 is highly advised, and you should upgrade as soon as possible.

pip2 OR pip3 VS APT Package Manager

A common question is whether we should utilize APT or pip. Every user has to make a decision here. While pip is used to get and install applications directly from PyPI, APT is faster but more out of date. For those who don't know, Python Software Foundation hosts PyPI, a package manager that only handles Python packages, many of which are more up to date than those offered by Canonical through APT. The packages may take longer to install when using pip through PyPI, but that is the only negative.

In this tutorial, you will install Python pip3 or pip2 on Debian 11. We will also address a few FAQs on how to install Python pip3 or pip2 on Debian 11.

Advantages of pip

  1. Easy installation: The pip allows for convenient installation of Python packages with a simple command.
  2. Large package repository: With an extensive library of packages, pip provides access to a wide range of functionality for developers.
  3. Package management: The pip enables efficient management of installed packages, making it easier to update, uninstall, or resolve dependencies.
  4. Virtual environment integration: The pip seamlessly integrates with virtual environments, allowing for isolated environments and easy package version control.
  5. User-friendly command-line interface: With a straightforward and intuitive CLI, pip ensures a smooth and efficient user experience for managing Python packages.

Update System

Make sure all installed packages are latest by updating your Debian operating system:

sudo apt update && sudo apt upgrade -y

Install Python 2

Debian 11 comes with Python 3 preinstalled. Nevertheless, those who require Python 2 can install it using either the python or python2 command.

Use the following command to install Python2, which will subsequently make use of pip2.

sudo apt install python -y

Following that, head over to Install pip and install the corresponding version for your Python installation.

Check the version build to first confirm the installation, or if Python or Python2 is installed.

python --version

Example output:

Python 2.7.18

Install Python 3

As previously indicated, Python 3 ought to be preinstalled; if it isn't, you may re-install it with the following command.

sudo apt install python3 -y

Install the corresponding version of pip for your Python installation after that by going to install pip.

Check the version build to see if Python3 has already been installed or to confirm the installation.

python3 --version

Example output:

Python 3.9.2

Install pip 2

You must manually download the helpful script in order to install pip on Debian 11 because it is no longer included in the default repository.

The CURL package must first be installed.

sudo apt install curl -y

The .py script must be downloaded in order to install pip2:

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

Run the .py script now:

sudo python2 get-pip.py

To continue with the installation, type Y and then press the enter key.

Run the following version command to see if pip2 was successfully installed:

pip2 --version

Example output:

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

As soon as feasible, pip2 and Python 2 should be upgraded to Python 3 and pip 3, as this has reached its end of life.

Install pip 3

Use the following command to install pip3(For Python 3+):

sudo apt install python3-pip 

Run the following version command to see if pip3 was successfully installed:

pip3 --version 

Example output:

pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)
💡
Please note that this version number is simply an example and will change over time.

pip Terminal Commands Example

Running the pip command list and search will allow you to quickly browse through some of the many packages that can be installed using pip. Needless to say, with a minor modification, the commands will operate on pip and pip3 as well.

Below are a few examples from the tutorial for pip3.

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

pip3 --help

The following example shows how to use pip3 help and how to get download assistance:

pip3 download --help

Use the following to list packages that can be installed on pip3:

pip3 --list

If you wish to narrow down the list, utilize the search option as follows:

pip3 search PACKAGE_NAME

Use this command to install a package using pip3:

pip3 install numpy

The NumPy package was installed in the above-mentioned example.

The following command should be used to uninstall a pip3 package:

sudo pip3 uninstall numpy

To finish the uninstallation, enter Y and press ENTER.

Example output:

Successfully uninstalled numpy-1.21.3

Remove (Uninstall) pip

Depending on the version you have installed, use the commands below to uninstall pip from your Debian system.

To remove pip:

sudo python -m pip uninstall pip

To finish the uninstallation, enter Y and press ENTER.

Successfully uninstalled pip-20.3.4

To remove pip3:

sudo apt autoremove python3-pip --purge

To finish the uninstallation, enter Y and press ENTER.

FAQs to Install Python pip3 or pip2 on Debian 11

Can I install both pip2 and pip3 on Debian 11?

Yes, you can have both pip2 and pip3 installed simultaneously on Debian 11 without any conflicts.

What's the difference between pip2 and pip3?

pip2 is for Python 2.x, while pip3 is used for Python 3.x. Debian 11 predominantly supports Python 3, so it's recommended to use pip3.

What if the pip3 command is not recognized on Debian 11? 

You may need to ensure pip3 is installed correctly. Try reinstalling it using the command sudo apt install python3-pip.

What is the difference between pip2 and pip3?

pip2 is for Python 2.x, while pip3 is for Python 3.x. pip3 is the commonly used version, as Python 2 is deprecated.

Are there any alternative package managers to pip for Debian 11?

While pip is the recommended package manager for Python, you can also use alternative tools like "Anaconda" or "easy_install".

Do I need to use virtual environments with pip on Debian 11?

Although not mandatory, using virtual environments with pip is highly recommended for better package management and isolation.

Can I install Python packages globally using pip on Debian 11?

Yes, pip can install packages system-wide. However, it's generally recommended to use virtual environments to avoid conflicts between projects.

Conclusion

You now know how to install pip for Python or Python 3 and search, install, and remove packages on Debian 11 Bullseye. If you have any queries or doubts, please leave them in the comment below. We'll be happy to address them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.