Ricerca nel sito web

Come installare e utilizzare PIP Python Package Manager su Debian 11


Su questa pagina

  1. Prerequisiti
  2. Installa Pip per Python3
  3. Installa Pip per Python2
  4. Come utilizzare la riga di comando Pip
  5. Conclusione

Pip è un gestore di pacchetti ampiamente utilizzato per il linguaggio di programmazione Python. Viene utilizzato per installare e gestire pacchetti aggiuntivi che non sono disponibili nella libreria standard di Python. Consente agli utenti di cercare un pacchetto dall'indice dei pacchetti Python e di installarne le dipendenze. Pip è anche noto come \Programma di installazione preferito\ che può creare un ambiente completamente isolato per l'applicazione Python.

In questo articolo, ti mostrerò come installare e utilizzare Pip su Debian 11.

Prerequisiti

  • Un server che esegue Debian 11.
  • Sul server è configurata una password di root.

Installa Pip per Python3

Per impostazione predefinita, Pip non è installato nel sistema operativo Debian 11. Dovrai installare versioni Pip separate per Python3 e Python2.

Innanzitutto, installa Python3 con il seguente comando:

apt-get install python3 -y

Una volta installato il pacchetto Python3, installa il Pip per Python3 usando il seguente comando:

apt-get install python3-pip -y

Successivamente, verifica la versione Pip utilizzando il seguente comando:

pip3 --version

Otterrai il seguente output:

pip 20.3.4 from /usr/lib/python3/dist-packages/pip (python 3.9)

Installa Pip per Python2

Innanzitutto, dovrai installare Python2 sul tuo sistema. Puoi installarlo usando il seguente comando:

apt-get install python2 curl -y

Successivamente, scarica lo script di installazione di Pip2 utilizzando il seguente comando:

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py

Quindi, esegui lo script scaricato per installare Pip2 sul tuo sistema.

python2 get-pip.py

Una volta installato, puoi verificare la versione Pip2 usando il seguente comando:

pip2 --version

Otterrai il seguente output:

pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

Come utilizzare la riga di comando Pip

Per elencare tutte le opzioni disponibili con Pip, esegui il seguente comando:

pip3 --help

Otterrai il seguente elenco:

Usage:   
  pip3  [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip's wheel cache.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

Per installare qualsiasi pacchetto per Python3 come TextStatistic, esegui il seguente comando:

pip3 install "TextStatistic"

Esempio di output:

Collecting TextStatistic
  Downloading TextStatistic-1.0.6-py3-none-any.whl (5.6 kB)
Installing collected packages: TextStatistic
Successfully installed TextStatistic-1.0.6

Per installare qualsiasi pacchetto per Python2 come scrapy, esegui il seguente comando:

pip install "scrapy"

Per elencare tutti i pacchetti disponibili, eseguire il seguente comando:

pip3 list

Dovresti vedere il seguente output:

Package          Version
---------------- ---------
certifi          2020.6.20
chardet          4.0.0
httplib2         0.18.1
idna             2.10
pip              20.3.4
pycurl           7.43.0.6
PySimpleSOAP     1.16.2
python-apt       2.2.1
python-debian    0.1.39
python-debianbts 3.1.0
reportbug        7.10.3
requests         2.25.1
setuptools       52.0.0
six              1.16.0
TextStatistic    1.0.6
urllib3          1.26.5
wheel            0.34.2

Per cercare qualsiasi pacchetto, esegui il seguente comando:

pip3 search urllib3

Per elencare i pacchetti obsoleti, eseguire il seguente comando:

pip3 list --outdated

Otterrai il seguente output:

Package          Version   Latest    Type
---------------- --------- --------- -----
certifi          2020.6.20 2021.10.8 wheel
httplib2         0.18.1    0.20.1    wheel
idna             2.10      3.3       wheel
pip              20.3.4    21.3      wheel
pycurl           7.43.0.6  7.44.1    sdist
python-debian    0.1.39    0.1.40    wheel
python-debianbts 3.1.0     3.2.0     wheel
requests         2.25.1    2.26.0    wheel
setuptools       52.0.0    58.2.0    wheel
urllib3          1.26.5    1.26.7    wheel
wheel            0.34.2    0.37.0    wheel

Per visualizzare le informazioni di qualsiasi pacchetto, eseguire il seguente comando:

pip3 show wheel

Dovresti vedere le informazioni del pacchetto ruote nel seguente output:

Name: wheel
Version: 0.34.2
Summary: A built-package format for Python
Home-page: https://github.com/pypa/wheel
Author: Daniel Holth
Author-email: 
License: MIT
Location: /usr/lib/python3/dist-packages
Requires: 
Required-by: 

Per disinstallare qualsiasi pacchetto, eseguire il seguente comando:

pip3 uninstall scrapy

Conclusione

Nella guida sopra, abbiamo spiegato come installare Pip3 e Pip2 su Debian 11. Abbiamo anche spiegato come utilizzare il comando Pip per installare e gestire i pacchetti Python. Spero che ora tu possa gestire facilmente le dipendenze di Python usando il comando Pip.