升级pip报错ERROR: Could not install packages due to an OSError: [WinError 5]
今天在安装python第三方库时,提示pip需要升级,没有多想直接升级,结果报错:
1 ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: 'd:\\python\\scripts\\pip.exe' 2 Consider using the `--user` option or check the permissions.
一、报错处理
从报错信息看,大概是权限问题,于是使用管理员身份运行CMD,再次升级依旧报错。
D:\Python\Lib\site-packages>pip install --upgrade pip Requirement already satisfied: pip in d:\python\lib\site-packages (21.1.1) Collecting pip Downloading pip-23.0.1-py3-none-any.whl (2.1 MB) |████████████████████████████████| 2.1 MB 2.2 MB/s Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 21.1.1 Uninstalling pip-21.1.1: ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: 'd:\\python\\scripts\\pip.exe' Consider using the `--user` option or check the permissions.
升级时PyCharm未关闭,联想到之前处理过的报错,查看了 D:\Python\Lib\site-packages 目录,果然pip
相关的两个文件夹已经不在了。此时执行命令报错:
D:\Python\Lib\site-packages>pip install --upgrade pip Traceback (most recent call last): File "d:\python\lib\runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "d:\python\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "D:\Python\Scripts\pip.exe\__main__.py", line 4, in <module> ModuleNotFoundError: No module named 'pip'
最终解决方法,先执行 python -m ensurepip 命令,再升级pip。
D:\Python\Lib\site-packages>python -m ensurepip WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) Looking in links: c:\Users\EDISON~1\AppData\Local\Temp\tmphubo0umq Requirement already satisfied: setuptools in d:\python\lib\site-packages (56.0.0) Processing c:\users\edisonyao\appdata\local\temp\tmphubo0umq\pip-21.1.1-py3-none-any.whl WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) Installing collected packages: pip WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) Successfully installed pip-21.1.1
D:\Python\Lib\site-packages>python -m pip install --upgrade pip WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) Requirement already satisfied: pip in d:\python\lib\site-packages (21.1.1) Collecting pip Using cached pip-23.0.1-py3-none-any.whl (2.1 MB) WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) Installing collected packages: pip Attempting uninstall: pip WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) Found existing installation: pip 21.1.1 Uninstalling pip-21.1.1: Successfully uninstalled pip-21.1.1 WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) Successfully installed pip-23.0.1 WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages) WARNING: Ignoring invalid distribution -ip (d:\python\lib\site-packages)
二、命令释义
ensurepip 包为在已有的Python安装实例或虚拟环境中引导 pip 安装器提供了支持。需要使用引导才能使
用pip的这一事实也正好反映了 pip 是一个独立的项目,有其自己的发布周期,其最新版本随CPython解释器的
维护版本和新特性版本一同捆绑。
在大多数情况下,Python的终端使用者不需要直接调用这个模块( pip 默认应该已被引导),不过,如果
在安装Python(或创建虚拟环境)时跳过了安装 pip 步骤,或者使用过程中卸载了 pip ,则需要使用这个模块。
最常用的调用命令: python -m ensurepip ,其含义是在未安装pip的情况下安装pip,若已安装则不做任
何处理。
作者:Sweettesting —— 半醉半醒半浮生
出处:http://www.cnblogs.com/Sweettesting/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。