pip更新及Requirement already up-to-date解决方法

时间:2022-05-05 19:10:30

pip更新及Requirement already up-to-date解决方法

文:铁乐与猫

2018-9-11

更新命令

  • 将pip更新到最新版本
python -m pip install --upgrade pip
  • Anaconda更新命令为
conda install mingw libpython

Requirement already up-to-date

在pycharm的虚拟环境中,特别容易出现运行更新pip的命令后,提示要求己经更新,但实际上查看版本还是没更新成功的情况:

(venv) E:\Flask\BaiduAI>pip --version
pip 9.0.1 from e:\flask\baiduai\venv\lib\site-packages\pip-9.0.1-py3.6.egg (python 3.6) (venv) E:\Flask\BaiduAI>python -m pip install --upgrade pip
Requirement already up-to-date: pip in e:\flask\baiduai\venv\lib\site-packages (18.0) (venv) E:\Flask\BaiduAI>pip --version
pip 9.0.1 from e:\flask\baiduai\venv\lib\site-packages\pip-9.0.1-py3.6.egg (python 3.6)

直接使用pip install --upgrade pip 命令还会出现权限不足的报错:


(venv) E:\Flask\BaiduAI>pip install --upgrade pip
Cache entry deserialization failed, entry ignored
Collecting pip
Using cached https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf94
0/pip-18.0-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Exception:
Traceback (most recent call last):
File "D:\PortableSoft\Python36\lib\shutil.py", line 544, in move
os.rename(src, real_dst)
OSError: [WinError 17] 系统无法将文件移到不同的磁盘驱动器。: 'e:\\flask\\baiduai\\venv\\scripts\\pip.exe' -> 'C:\\Users\
\ADMINI~1\\AppData\\Local\\Temp\\pip-76ifpsoa-uninstall\\flask\\baiduai\\venv\\scripts\\pip.exe' During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "e:\flask\baiduai\venv\lib\site-packages\pip-9.0.1-py3.6.egg\pip\basecommand.py", line 215, in main
File "e:\flask\baiduai\venv\lib\site-packages\pip-9.0.1-py3.6.egg\pip\commands\install.py", line 342, in run
File "e:\flask\baiduai\venv\lib\site-packages\pip-9.0.1-py3.6.egg\pip\req\req_set.py", line 778, in install
File "e:\flask\baiduai\venv\lib\site-packages\pip-9.0.1-py3.6.egg\pip\req\req_install.py", line 754, in uninstall
File "e:\flask\baiduai\venv\lib\site-packages\pip-9.0.1-py3.6.egg\pip\req\req_uninstall.py", line 115, in remove
File "e:\flask\baiduai\venv\lib\site-packages\pip-9.0.1-py3.6.egg\pip\utils\__init__.py", line 267, in renames
File "D:\PortableSoft\Python36\lib\shutil.py", line 559, in move
os.unlink(src)
PermissionError: [WinError 5] 拒绝访问。: 'e:\\flask\\baiduai\\venv\\scripts\\pip.exe'

这简直是死循环了,使用python -m pip install --upgrade pip -vvv

报了一大堆信息,然而也没有什么卵用。

后来细想有可能是因为我之前是使用pycharm尝试升级虚拟环境里的pip版本,显示是成功升级到18.0了的缘故。

有及于此,最后我是跑到E:\Flask\BaiduAI\venv\Lib\site-packages 目录下查看,发现了在没有安装成功18.0版本的时候此目录下就己存在pip-18.0.dist-info,有毛病。

pip更新及Requirement already up-to-date解决方法

于是大胆尝试将pip-18.0.dist-info目录删除后,继续在虚拟环境下重新更新pip,终于成功!

(venv) E:\Flask\BaiduAI>python -m pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf94
0/pip-18.0-py2.py3-none-any.whl
Installing collected packages: pip
Successfully installed pip-18.0 (venv) E:\Flask\BaiduAI>pip --version
pip 18.0 from e:\flask\baiduai\venv\lib\site-packages\pip (python 3.6)

这个报错告诉我,尽量选择在cmd命令行下手动更新pip或其它软件包,而不要选择在pycharm的界面下直接用鼠标点升级……

【end】