GNU/Linux >> Linux Esercitazione >  >> Debian

Python:il modo corretto per aggiornare Pip in Stretch Debian?

Ho esaminato alcune note sul fatto che non è una buona idea eseguire l'aggiornamento di pip usando il comando sudo. La mia domanda è se non do sudo ottengo errori di autorizzazione. Come posso risolvere questo? Inoltre, qual è il motivo per cui sudo non è suggerito per aggiornare pip?

$python -m pip install --upgrade pip
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting pip
  Using cached https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 19.2.3
    Uninstalling pip-19.2.3:
      Successfully uninstalled pip-19.2.3
  Rolling back uninstall of pip
  Moving to /home/abc/.local/bin/pip
   from /tmp/pip-uninstall-V4F8Pj/pip
  Moving to /home/abc/.local/bin/pip2
   from /tmp/pip-uninstall-V4F8Pj/pip2
  Moving to /home/abc/.local/bin/pip2.7
   from /tmp/pip-uninstall-V4F8Pj/pip2.7
  Moving to /home/abc/.local/lib/python2.7/site-packages/pip-19.2.3.dist-info/
   from /home/abc/.local/lib/python2.7/site-packages/~ip-19.2.3.dist-info
  Moving to /home/abc/.local/lib/python2.7/site-packages/pip/
   from /home/abc/.local/lib/python2.7/site-packages/~ip
ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip-20.0.2.dist-info/top_level.txt'
Consider using the `--user` option or check the permissions.

WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Risposta accettata:

Non aggiornare mai la versione degli strumenti fornita dal sistema operativo al di fuori del sistema di gestione dei pacchetti, perché se viene rilasciato un nuovo pacchetto, le modifiche verranno sovrascritte.

Quindi sudo pip install --upgrade pip è una brutta cosa. Il sistema di pacchetti del sistema operativo crede di controllare i file e li hai sovrascritti. Potrebbero verificarsi comportamenti strani, inclusa l'installazione di un precedente versione di quella che hai installato in precedenza!

Se desideri una versione più recente, puoi installarla nel profilo utente

% pip install --upgrade --user pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl (1.4MB)
    100% |################################| 1.4MB 615kB/s 
Installing collected packages: pip
Successfully installed pip-20.0.2

Questo installerà l'ultima versione in $HOME/.local/bin

% ls -l .local/bin/pip                                           
-rwxr-xr-x 1 sweh sweh 223 Feb 16 21:49 .local/bin/pip

Se hai $HOME/.local/bin sul tuo PERCORSO, raccoglierai sempre i programmi installati dall'utente su pip.

La maggior parte delle volte, tuttavia, non è necessario per aggiornare pip .


Debian
  1. Costruire kernel Linux alla maniera Debian

  2. Come aggiornare Debian 8 Jessie a Debian 9 Stretch

  3. Come modificare la versione Python predefinita su Debian 9 Stretch Linux

  4. Come installare Pip su Ubuntu 18.04, Debian 9 e Linux Mint 19

  5. Come aggiornare Debian 8 a Debian 9 Stretch

Come aggiornare da Debian 9 Stretch a Debian 10 Buster

Come aggiornare da Debian 8 Jessie a Debian 9 Stretch

Aggiorna Debian 9 Stretch a Debian 10 Buster dalla riga di comando

Come installare Pip su Debian 9 Stretch

Come installare Python 3.7 su Debian 9 Stretch

Come aggiornare Debian 9 Stretch a Linux Debian 10 Buster