Python 3 不是升级pip。我是否链接了错误的目录?

Python 3 is not upgrading pip. Am I linking a wrong directory?

每次尝试在 Python 3 中安装软件包时,我都会遇到以下问题:

WARNING: You are using pip version 20.2.4; however, version 20.3.1 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command

我尝试按如下方式执行升级 pip 命令,但也出现以下警告:

$ pip3 install --upgrade pip

Collecting pip
  Using cached pip-20.3.1-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Successfully installed pip-20.3.1
WARNING: You are using pip version 20.2.4; however, version 20.3.1 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command

我试了另外一种方法,同样的错误:

$ /usr/bin/python3 -m pip install --upgrade pip

Collecting pip
Using cached pip-20.3.1-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Successfully installed pip-20.3.1
WARNING: You are using pip version 20.2.4; however, version 20.3.1 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command

我也试过 ,下载包并要求 pip 直接从 .tar.gz 文件安装:

$sudo python3 -m pip install /home/me/Downloads/pip-20.3.1.tar.gz 

[sudo] password for me: 
Processing /home/me/Downloads/pip-20.3.1.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: pip
  Building wheel for pip (PEP 517) ... done
  Created wheel for pip: filename=pip-20.3.1-py2.py3-none-any.whl size=1518515 sha256=36207044a2b9042728f3cd0f971569217f4e2e9c68c84adbf5c42617e08b9d3c
  Stored in directory: /root/.cache/pip/wheels/0e/09/b2/4673e6d2eee911dbbeaeeba8e68eebb9719b1b3ba25ad93e2c
Successfully built pip
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.0.2
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
    Can't uninstall 'pip'. No files were found to uninstall.
Successfully installed pip-20.3.1

再次发生同样的错误:

$pip3 install pydot

Collecting pydot
Using cached pydot-1.4.1-py2.py3-none-any.whl (19 kB)
Collecting pyparsing>=2.1.4
Using cached pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
Installing collected packages: pyparsing, pydot
Successfully installed pydot-1.4.1 pyparsing-2.4.7

WARNING: You are using pip version 20.2.4; however, version 20.3.1 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.

我的 Python 版本是:

$python --version
Python 3.7.9

$python3 --version
Python 3.8.5

我的 PATH 变量 link 是以下目录:

$echo $PATH

/home/me/.local/bin:/home/me/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

这里发生了什么?我是否必须向我的 PATH 变量添加一些内容才能 link 正确的 python 版本到 pip upgrade 命令?或者还有其他事情要做?

只需使用 sudo 进行 pip3 升级即可。我认为您将 python2 和 python3 安装与 sudo 调用混淆了。 刚刚测试并在 pip3 上给了我正确的版本:

$ sudo pip3 install --upgrade pip
Collecting pip
  Downloading pip-20.3.1-py2.py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 2.6 MB/s 
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.0.2
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
    Can't uninstall 'pip'. No files were found to uninstall.
Successfully installed pip-20.3.1
$ pip3 --version
pip 20.3.1 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)

在 KDE Neon (Ubuntu 20.04) 上测试。 还要确保您没有在用户安装的某处安装其他版本的 pip。这些很容易混淆 python 安装的 apt 和用户位置。

您正在使用 pip 版本 19.2.3,但是版本 20.3.4 可用。 您应该考虑通过 'pip install --upgrade pip' 命令升级。