How to Install pip on Debian 11, 12, and 13

By 

Updated on

5 min read

Install Python pip on Debian 11, 12, and 13

Pip is a tool for installing Python packages. With pip, you can search, download, and install packages from the Python Package Index (PyPI) and other package indexes.

This tutorial explains how to install pip for Python 3 (pip3) on Debian 11, 12, and 13 using the apt package manager.

We will also show you how to install and manage Python packages with pip.

Quick Reference

For a printable quick reference, see the Python cheatsheet .

CommandDescription
pip3 install packageInstall a package
pip3 install package==1.0.0Install a specific version
pip3 install --upgrade packageUpgrade an installed package
pip3 install -r requirements.txtInstall from a requirements file
pip3 uninstall packageRemove a package
pip3 listList all installed packages
pip3 show packageShow details about a package
pip3 freezeOutput installed packages in requirements format

Installing pip on Debian

Pip for Python 3 is included in the default Debian repositories, and the installation is pretty straightforward.

Info
Python 2 reached end of life on January 1st, 2020. Python 2 packages are not available in Debian 11, 12, or 13 repositories.

Run the following commands to refresh the local package index and install pip and all of its dependencies:

Terminal
sudo apt update
sudo apt install python3-pip

To ensure that pip has been installed correctly on your system, you can check its version by typing:

Terminal
pip3 --version

The version number may be different, but it will look something like the one below:

output
pip 23.0.1 from /usr/lib/python3/dist-packages/pip (python 3.11)

When a new version is released, you can update the python3-pip package through the command line or your desktop Software Update tool.

Using pip

With pip, you can install packages from PyPI and other sources, manage package versions, update packages, remove packages and more.

Python modules can be installed globally (accessible for all projects and users) or on a project basis.

If you want to install a Python module globally, you should prefer to install it as a package using the apt manager. Use pip to install Python modules globally only if no package is available.

Pip is mostly used inside a virtual environment. A Python virtual environment allows you to install Python modules in an isolated location for a specific project rather than being installed globally. This prevents issues caused by shared dependencies and libraries.

If you want to upgrade pip itself on Debian 12 or 13, do it inside a virtual environment rather than in the system Python environment:

Terminal
python3 -m venv myenv
source myenv/bin/activate
pip3 install --upgrade pip

To get a list of all pip commands and options, type:

Terminal
pip3 --help

You can get more information about a specific command using pip3 <command> --help. For example, to get more information about the install command, type:

Terminal
pip3 install --help

Installing Packages with pip

Warning
Starting with Debian 12, the system Python environment is marked as externally managed (PEP 668). Running pip3 install package directly will fail with an externally-managed-environment error. The recommended approach is to use a virtual environment for installing packages.

To install packages with pip, first create and activate a virtual environment:

Terminal
python3 -m venv myenv
source myenv/bin/activate

Then install packages as usual:

Terminal
pip3 install package_name

To install a specific version of a package, append == and the version number after the package name:

Terminal
pip3 install tensorflow==2.13.0

Installing Packages Using a Requirements File

requirements.txt is a text file containing a list of pip packages and their versions required to run a specific Python project.

To install a list of requirements specified in a file, use the following command:

Terminal
pip3 install -r requirements.txt

Listing Installed Packages

To list all the installed pip packages, use the list subcommand:

Terminal
pip3 list

Upgrading a Package with pip

To upgrade an already installed package to the latest version, enter:

Terminal
pip3 install --upgrade package_name

Uninstalling Packages with pip

To uninstall a package, run:

Terminal
pip3 uninstall package_name

FAQ

Does the installation differ between Debian 11, 12, and 13? The apt install python3-pip command works the same on all three versions. The main difference is that Debian 12 and 13 enforce PEP 668, which prevents pip from installing packages directly into the system Python environment. Use a virtual environment instead.

What is the externally-managed-environment error? This error appears on Debian 12 and 13 when you run pip3 install outside a virtual environment. It protects the system Python from conflicting packages. Create a virtual environment with python3 -m venv myenv and activate it before installing packages.

How do I use pip inside a virtual environment? Run python3 -m venv myenv to create the environment, then source myenv/bin/activate to activate it. Once active, pip3 install package installs packages only within that environment. See the Python virtual environments guide for more detail.

How do I save installed packages to a requirements file? Run pip3 freeze > requirements.txt to write all currently installed packages and their versions to a file. You can then reproduce the environment on another system with pip3 install -r requirements.txt.

Conclusion

We have shown you how to install pip on Debian 11, 12, and 13 and how to manage Python packages using pip. For more information about pip, visit the pip user guide page.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page