How to Install Pip on Debian 12

Pip (Python Install Packages) is used to manage the packages of Python including the installation, updation, and deletion of packages. It can be installed on the latest version of Debian, Debian 12 Bookworm, which was released in June 2023. 

In this post, we will go through the installation method of Pip and its basic usage on Debian 12 in a step-by-step guide. 

What is Pip?

Pip is the abbreviated Python Install Packages used to manage the packages of Python. It installs the packages from the repository of the Python Package Index. It also includes the dependencies and libraries which are needed for the smooth usage of Python applications.

Pip provides not only a vast repository of Python packages but also provides ease in managing the packages on the computer. 

How to Install Pip on Debian 12 Using the Default Repository

To install Pip on Debian 12, use the below-mentioned steps, however, before that make sure all the packages are up to date:

$ sudo apt update
Install Pip on Debian 12 a

Proceed to the below steps after ensuring all the packages are up to date. 

Step 1: Install the Pip Package for Python

If Python2 is being installed on your computer then use the command:

$ sudo apt install python-pip -y
Install Pip on Debian 12 b

Use the command if you are using Python3 on Debian 12:

$ sudo apt install python3-pip -y
Install Pip on Debian 12 c

Step 2: Display the Version of Pip

Now find the version of the installed package of Pip with the execution of the below-mentioned command:

$ pip --version

What is the “error: externally-managed-environment” in pip?

Some users might have problems with the usage of the pip command in Python versions greater than 11.  This error can be resolved either by using the pip commands in the separate virtual environment following the blog or by removing the “EXTERNALLY-MANAGED” file following the steps explained in this section. 

We tried to install the Python package “lxml” with the pip command and the mentioned error has been displayed:

To resolve this simply remove the “EXTERNALLY-MANAGED” file from the Debian with the rm command:

$ sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED

The error has been resolved in Debian 12 successfully. 

Note: However, it is recommended to manage the Python packages in the separate Python virtual environment instead of removing the EXTERNALLY-MANAGED file.

How to Manage the Python Packages Using the Pip?

To manage the Python packages using Pip, different commands can be executed as explained below.

To List Down Python Packages

Pip contains a variety of Python packages which can be listed using the command:

$ pip list
Install Pip on Debian 12 e

It will display all the available Python packages on the Pip repository. 

To Search Python Packages

Among the complete list of Python packages in the Pip repository, any particular package can be searched by following the general syntax:

$ pip search [package name]

To Download Python Packages

First, download the Python package which is supposed to install. For example, download the “six” package:

$ pip download six
Install Pip on Debian 12 f

To Install Python Packages

To install the Python packages using Pip, use the general syntax:

$ sudo pip install [package name]

For understanding, install the Python package “lxml” with the above command:

$ sudo pip install lxml

To Show Python Package

One can also display the Python package information available in the Pip repository by using the “show” option. For example, display the information of the “six” python package:

$ sudo pip show six
Install Pip on Debian 12 g

To Uninstall the Python Package

To uninstall the installed Python package using Pip, use the “uninstall” option of Pip. 

$ sudo pip uninstall [Package Name]

For example, uninstall the “lxml” package following the above command:

$ sudo pip uninstall lxml

How to Uninstall the Pip on Debian 12?

To uninstall the package of the Pip on Debian 12, use the “purge” option of the apt package manager. This will remove the Pip package with all its dependencies:

$ sudo apt purge python3-pip -y
Install Pip on Debian 12 h

This is the way the Pip package can be used to manage the Python Packages on Debian 12.

Conclusion

To install the Pip package on Debian 12, use the default repository of Debian 12 by executing the command “sudo apt install python-pip -y”. The Pip package is used to manage the Python packages by using the Python Package Index repository. This post has explained two different methods of installing Pip on Debian 12. Also, the basic usage of Pip on Debian 12 has been explained.