如何解决pip安装失败问题?Windows11+Python3.11.5环境报错
问题描述
系统环境:Windows 11,Python 3.11.5
执行pip install numpy时出现如下报错,且安装任何Python包都会触发相同错误:
C:\Users\awmvi>pip install numpy WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))': /simple/numpy/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))': /simple/numpy/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))': /simple/numpy/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))': /simple/numpy/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))': /simple/numpy/ ERROR: Could not find a version that satisfies the requirement numpy (from versions: none) ERROR: No matching distribution found for numpy
解决方法
检查并清空pip代理配置
连接中断错误大概率和代理设置有关。先查看当前代理:pip config get global.proxy如果返回代理地址,执行以下命令清空:
pip config unset global.proxy之后重新尝试安装。
切换国内PyPI镜像源
默认PyPI源在国内网络下易不稳定,可临时指定国内镜像安装:pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple若临时生效,可配置永久使用国内源:
- 在用户目录(如
C:\Users\awmvi)下创建pip文件夹 - 新建
pip.ini文件,写入:[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple
- 在用户目录(如
修复或重装pip
pip本身损坏也会引发这类问题,执行以下命令重装pip:python -m ensurepip --upgrade或者用官方脚本重装:
curl https://bootstrap.pypa.io/get-pip.py | python排查防火墙/杀毒软件拦截
临时关闭系统防火墙和杀毒软件,再尝试安装。如果问题解决,将pip程序添加到信任列表。验证Python环境变量
确保Python和pip的路径已加入系统环境变量:- 右键「此电脑」→「属性」→「高级系统设置」→「环境变量」
- 在系统变量的
Path中,确认包含Python安装目录(如C:\Python311)和Scripts目录(如C:\Python311\Scripts) - 未添加则手动补充,之后重启命令提示符。
内容的提问来源于stack exchange,提问作者Fringo Friends
相关产品推荐
相关产品推荐

