python - Python 3 没有升级 pip。我是否链接了错误的目录?
问题描述
每次尝试在 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 变量链接以下目录:
$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 变量中添加一些内容才能将正确的 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。这些很容易在 apt 和 python 安装的用户位置之间混淆。
推荐阅读
- r - R中的递归类
- javascript - 难以理解从文件控件中检索文件名的代码
- c# - 从最近的任务中删除应用程序时,Android 通知会被取消
- flutter - 如何在flutter中使用sharedpreference保存事件
- android - 强制 Android TalkBack 停留在一个视图层次结构中
- excel - Excel:我想根据单词修饰符列表对列进行排序
- python - 为什么 Python 中的 a / (b*c) 比 a / b / c 慢(一般来说)?
- javascript - 使用 gulp 脚本缩小 js
- php - 如何从服务提供者绑定或注入变量到模型类 laravel
- sql-server - Visual Studio Data Tools 没有显示所有列