How to Install Pip on Debian 12?


Pip (Python Install Packages) is a cross-platform package management tool for Python modules and packages. Python usually comes with limited built-in packages. Python packages developed by Python developers are stored and regularly updated in the Python Package Index (PyPI), which is a dedicated software repository for Python. Pip enables a user to search and install third-party packages from PyPI.

This article will demonstrate the installation of PIP on Debian 12, with the following outline:

Let’s begin by identifying the prerequisites for installing Pip on Debian 12.

Prerequisites: How to Install Python 3?

In order to install and use pip, installation of Python is required. First, update the system packages:


Next, install python3 by running the below-mentioned command:


The above output indicates that Python is updated to the latest version.

Note: Debian 12 no longer supports Python 2 and ships with Python3.

How to Install Pip on Debian 12?

Pip is not pre-installed in the Debian 12 systems. In this section, pip will be installed by Debian’s default packet manager, i.e., Apt (Advanced Package Tool), using the following steps:

Step 1: Update System Repositories

Update the system packages list using the following command:


Step 2: Install Pip

To manage Python packages, install pip by running the below command:

sudo apt install python3-pip

Step 3: Verify Pip Installation

To verify pip installation, run the following command:

Check the pip version by checking the version by the following command:


Where pip3 is the command used when managing Python3 packages. The above output signifies that the latest version of pip, i.e., 23.0.1 is installed for Python 3.11.

How to Manage Pip on Debian 12?

Pip manages the Python packages that are installed on the system. In this section, the following package management approaches are demonstrated:

How to View Installed Python Packages via Pip on Debian 12?

The list command lists all the installed Python packages along with their respective versions, as follows:


The above figure displays the list of the installed Python packages on the system.

How to Show Information of a Specific Python Package on Debian 12?

The show command returns the details, like, version, summary, home page, author, license, location, etc of the specified installed package. To show information about installed Python packages, run the “pip3 show” command followed by the name of the Python package, as follows:

How to Install and Remove Python Packages on Debian 12?

In other Linux distributions, like Ubuntu, Mint, etc, and in Debian 11 and previous Debian versions, pip3 was also used to install and remove Python packages.

Note: In Debian 12, the system-wide installation of Python packages is not recommended using PIP. This is because PIP bypasses Debian’s package manager APT to install Python packages. The conflict between PIP and APT may invoke security risks and the breaking of critical system packages/ system crashes.

When a user attempts to download a Python Package via PIP as a system-wide package, the following error message is returned:


This error is returned as Debian 12 considers its Python installation to be externally managed. Further, to avoid breaking crucial system packages, it is recommended to use Debian’s package managers to install and remove Python packages.

To install/remove Python packages, Debian 12 recommends the following methods:

  • Install/Remove Python packages via apt.
  • Create/Setup a Python virtual environment and then install/remove the desired Python package.
  • Install/Uninstall Python package via pipx.

How to Install and Remove/Uninstall Python Packages via apt?

The following sections demonstrate the installation and removal of a Python package via APT packet manager:

How to Install Python Packages via apt?

Before the installation, verify if pandas is already installed by listing all the available Python packages:


The above output indicates that pandas is not installed. To install pandas, execute the following command:

sudo apt install python3-pandas

The above output demonstrates that pandas is successfully installed on the system.

How to Remove/Uninstall a Python Package on Debian 12?

This section will demonstrate the removal of Python package appdirs. First, verify the installation of the addirs package using the list command:


To remove the appdirs package, execute the following command:

sudo apt remove python3-appdirs

The above output verifies that the package appdirs is successfully removed.

How to Create/Setup a Python Virtual Environment and then Install and Remove Python Packages?

This section demonstrates the installation and removal of a Python package by first creating a Python virtual environment. The “venv” module creates and manages a virtual environment. It can be installed by executing the following command:

sudo apt install python3-venv -y

How to Install a Python Package in a Virtual Environment?

To install Python packages in Debian 12, first, set up a virtual environment by executing the following command:


Where venv1 is the path(name) to the virtual environment

Then, activate the virtual environment by executing the following script:


Finally, use the below pip3 command to install Pandas:


The pip3 command will install the Pandas package along with all its dependencies which is verified by executing the following command:


Pandas 2.1.3 is successfully installed.

How to Remove/Uninstall a Python Package in a Virtual Environment?

The Pandas package can be removed by executing the following command:


The above output verifies that Pandas 2.1.3 is successfully removed.

Exit the Python virtual environment by the exit command.

How to Install and Remove/Uninstall a Python Package via Pipx?

Pipx is a command line tool that installs Python applications and runs them in an isolated environment. To install pipx, execute the following command:


After installation of pipx, add it to $PATH by executing the following command:


How to Install a Python Package via Pipx?

To install a Python package numpy via pipx, run the following command:


Numpy 1.26.2 is installed successfully.

How to Remove a Python Package via Pipx?

To remove a Python Package “numpy” via pipx, execute the following command:

How to Uninstall Pip on Debian 12?

To uninstall pip along with all its dependencies from the system, execute the following command:

sudo apt autoremove python3-pip

To verify un-installation, run the following command to check pip’s version:


The above output verifies that the pip is uninstalled successfully.

That’s all about Pip (Python Install Packages) on Debian 12 systems.

Conclusion

To install pip on Debian 12 systems, execute the “sudo apt install python3-pip” command. Additionally, to verify the pip installation, check the pip version by executing the “pip3 –version” command. Debian 12 prohibits pip3 from managing the Python packages and its alternative is elaborated on as well. This article has demonstrated the installation, usage, and uninstallation of pip. Additionally, the ways to manage the Python packages recommended in Debian 12, are also provided.

Print Friendly, PDF & Email