原文链接:http://www.juzicode.com/archives/3861
错误提示:
升级pip时发生错误,OSError: [WinError 17] 系统无法将文件移到不同的磁盘驱动器。:
D:\dev\Python\Python36-32\Scripts>pip install --upgrade pip
Cache entry deserialization failed, entry ignored
Collecting pip
Using cached https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 9.0.3
Uninstalling pip-9.0.3:
Exception:
Traceback (most recent call last):
File "d:\dev\python\python36-32\lib\shutil.py", line 544, in move
os.rename(src, real_dst)
OSError: [WinError 17] 系统无法将文件移到不同的磁盘驱动器。: 'd:\\dev\\python\\python36-32\\scripts\\pip.exe' -> 'C:\\Users\\uit\\AppData\\Local\\Temp\\pip-ooupzlpu-uninstall\\dev\\python\\python36-32\\scripts\\pip.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\dev\python\python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
File "d:\dev\python\python36-32\lib\site-packages\pip\commands\install.py", line 342, in run
File "d:\dev\python\python36-32\lib\site-packages\pip\req\req_set.py", line 778, in install
File "d:\dev\python\python36-32\lib\site-packages\pip\req\req_install.py", line 754, in uninstall
File "d:\dev\python\python36-32\lib\site-packages\pip\req\req_uninstall.py", line 115, in remove
File "d:\dev\python\python36-32\lib\site-packages\pip\utils\__init__.py", line 267, in renames
File "d:\dev\python\python36-32\lib\shutil.py", line 559, in move
os.unlink(src)
PermissionError: [WinError 5] 拒绝访问。: 'd:\\dev\\python\\python36-32\\scripts\\pip.exe'
升级pip后提示ModuleNotFoundError: No module named ‘pip’
D:\dev\Python\Python36-32\Scripts>pip -V
Traceback (most recent call last):
File "d:\dev\python\python36-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\dev\python\python36-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\dev\Python\Python36-32\Scripts\pip.exe\__main__.py", line 5, in <module>
ModuleNotFoundError: No module named 'pip'
D:\dev\Python\Python36-32\Scripts>
错误原因:
1、使用pip升级pip本身时发生文件读写错误
解决方法:
1、需要先修复pip:
D:\dev\Python\Python36-32>python -m ensurepip
Requirement already satisfied: setuptools in d:\dev\python\python36-32\lib\site-packages
Collecting pip
Installing collected packages: pip
Successfully installed pip-9.0.3
2、再用python -m pip install –upgrade pip方法升级pip:
D:\dev\Python\Python36-32>python -m pip install --upgrade pip
Collecting pip
Using cached https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 9.0.3
Uninstalling pip-9.0.3:
Successfully uninstalled pip-9.0.3
Successfully installed pip-21.0.1
扩展内容:
如果本文还没有完全解决你的疑惑,你也可以在微信公众号“桔子code”后台给我留言,欢迎一起探讨交流。