在stretch debian中升级pip的正确方法是什么?

kur*_*m D 8 python pip

我已经看过一些笔记,说使用 sudo 命令进行 pip upgrade 不是一个好主意。我的问题是,如果我不给 sudo,我会收到权限错误。我该如何解决这个问题?另外,不建议使用 sudo 来升级 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.
Run Code Online (Sandbox Code Playgroud)

Ste*_*ris 12

切勿在软件包管理系统之外升级操作系统提供的工具版本,因为如果发布了新软件包,它将覆盖您的更改。

所以sudo pip install --upgrade pip是一件坏事。操作系统包系统认为它控制着文件,而你已经覆盖了它们。可能会导致奇怪的行为,包括安装比您之前安装的版本旧的版本!

如果您想要更新的版本,则可以将其安装在用户配置文件中

% 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
Run Code Online (Sandbox Code Playgroud)

这将安装最新版本 $HOME/.local/bin

% ls -l .local/bin/pip                                           
-rwxr-xr-x 1 sweh sweh 223 Feb 16 21:49 .local/bin/pip
Run Code Online (Sandbox Code Playgroud)

如果您$HOME/.local/bin在 PATH 上,那么您将始终选择用户 pip 安装的程序。

但是,大多数情况下,您不需要升级pip.