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:
- Prerequisites: How to Install Python3?
- How to Install Pip on Debian 12?
- How to Manage Pip on Debian 12?
- How to Uninstall Pip on Debian 12?
Let’s begin by identifying the prerequisites for installing Pip on Debian 12.
In order to install and use pip, installation of Python is required. First, update the system packages:
sudo apt update
Next, install python3 by running the below-mentioned command:
sudo apt install python3
The above output indicates that Python is updated to the latest version.
Note: Debian 12 no longer supports Python 2 and ships with Python3.
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:
Update the system packages list using the following command:
sudo apt update
To manage Python packages, install pip by running the below command:
sudo apt install python3-pip
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.
Pip manages the Python packages that are installed on the system. In this section, the following package management approaches are demonstrated:
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.
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:
pip3 show cryptography
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:
pip3 install pandas
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.
The following sections demonstrate the installation and removal of a Python package via APT packet manager:
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.
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.
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
To install Python packages in Debian 12, first, set up a virtual environment by executing the following command:
python3 -m venv venv1
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:
pip3 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.
The Pandas package can be removed by executing the following command:
pip3 uninstall pandas
The above output verifies that Pandas 2.1.3 is successfully removed.
Exit the Python virtual environment by the exit command.
Pipx is a command line tool that installs Python applications and runs them in an isolated environment. To install pipx, execute the following command:
sudo apt install pipx -y
After installation of pipx, add it to $PATH by executing the following command:
To install a Python package numpy via pipx, run the following command:
pipx install numpy
Numpy 1.26.2 is installed successfully.
To remove a Python Package “numpy” via pipx, execute the following command:
pipx uninstall numpy
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.
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.