How to install Pip on Debian 12

8 gen 2024 2 min di lettura
How to install Pip on Debian 12
Indice dei contenuti

Introduction

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 and 12 using the apt package manager.

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

Installing Pip on Debian

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

As of January 1, 2020, Python 2 is no longer supported. Python 2 packages are not available on the Debian 11 and 12 repositories.

Run the following commands to update the local package index and install Pip and all its dependencies:

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:

pip3 --version

The version number may be different, but it will look like this:

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 via the command line or 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 to all projects and users) or on a per-project basis.

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

Pip is primarily used within a virtual environment. Python Virtual Environment allows you to install Python modules in an isolated location for a specific project rather than being installed globally. This will avoid problems caused by dependencies and shared libraries.

In this section we will explore the basic usage of pip.

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

pip3 --help

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

pip3 install --help

Installing packages with Pip

The most basic function of the pip tool is to install a package.

To install the latest version of a package, run the following command:

pip3 install <package_name>

Let's say you want to install the tensorflow library. You can do this by typing:

pip3 install tensorflow

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

pip3 install tensorflow==2.13.0

Installing packages with Pip using requirements files

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

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

pip3 install -r requirements.txt

List of installed packages

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

pip3 list

Update a package with Pip

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

pip3 install --upgrade package_name

Uninstalling packages with Pip

To uninstall a package, run:

pip3 uninstall package_name

Conclusion

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

If you have any questions or feedback, please feel free to comment below.

Support us with a

Successivamente, completa il checkout per l'accesso completo a Noviello.it.
Bentornato! Accesso eseguito correttamente.
Ti sei abbonato con successo a Noviello.it.
Successo! Il tuo account è completamente attivato, ora hai accesso a tutti i contenuti.
Operazione riuscita. Le tue informazioni di fatturazione sono state aggiornate.
La tua fatturazione non è stata aggiornata.