Pip 无法安装任何软件包。

10

大约两周前,我开始无法下载Python包或访问pypi网站,而且在Chrome和Firefox上都是“无法访问的”。

当我尝试下载一个包时,会出现以下信息:

$ python -m pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose
Collecting numpy
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))': /simple/numpy/
  Could not find a version that satisfies the requirement numpy (from versions: )
No matching distribution found for numpy

我不知道为什么会发生这种情况,我没有更改我的计算机上的任何内容,它突然在两台电脑上出现了,我不明白。 有人知道为什么会这样吗?我已经搜索了几个小时,但找不到任何可以修复此错误的方法。
我尝试过以下方法: - 卸载所有Python程序并重新安装 - 检查我的驱动程序(你永远不知道) - 取消任何代理 - 禁用我的防火墙
操作系统:Windows 10

你使用的是什么操作系统? - Pedro Gomes
为什么要使用python -m pip install,而不是直接使用pip?在Windows操作系统上安装Python时,应该有一个选项来安装额外的包。选择该选项,还要选择类似于“导出环境变量”的选项。最后,您应该能够在cmd上简单地运行“pip install some_lib”。尝试一下,看看会发生什么。 - Pedro Gomes
它并不改变我通常使用pip install的方式,但我使用了这个命令,因为这是numpy网站上建议使用的命令。 - Shraneid
https://stackoverflow.com/search?q=%5Bpip%5D+Retry+after+connection+broken+by+ProtocolError+Connection+aborted+ConnectionResetError+An+existing+connection+was+forcibly+closed - phd
这可能是SSL错误或防火墙问题。或者两者都有。 - phd
显示剩余6条评论
7个回答

12

如果有人在寻找解决方案,我发现这个方法可能不是最优的,但至少它能够工作。使用以下命令代替pip install package

python.exe -m pip install package --proxy="proxy:port"

你可以在这里找到大量免费的代理:https://free-proxy-list.net/(请注意,并非所有代理都有效,您可能需要尝试多个才能找到一个可用的)

例如,你可以使用以下命令来安装numpy: python.exe -m pip install numpy --proxy="179.185.199.195:8080"


这对我有用,但你可以使用在Windows代理设置中找到的实际公司代理地址。Pip试图直接连接而不经过代理,导致防火墙将其拦截。 - pirsqua

2
使用上一个回答中提供的代理可能会暂时解决问题——如果你找到一个不会超时的代理,但这并不能解决问题,而且使用代理通常会降低下载速度。
我发现需要调查Python解释器位置,并确保虚拟环境没有引起问题。例如,如果setuptools无法更新,那么很可能已经有一部分代码或项目一直在使用setuptools,从而阻止其更新,而其他软件包需要新版本的setuptools才能安装。由于某种原因,这导致大多数软件包(如tensorflow、keras、pandas等)出现“ConnectionResetError: An existing connection was forcibly closed by the remote host”的情况。
在另一个空位置重建venv将重置任何软件包。
在Pycharm中执行此操作的方法:
File -> Settings
Project: -> Project Interpreter
Project Interpreter -> drop down list -> show all

Remove your current Python Interpreter location
Add New Environment

然后,您将被要求为项目提供位置: 在此处使用新位置将解决包安装的[Win10054] ConnectionResetError问题。
基本解释程序:指向python.exe的位置 (默认通常为:C:\Users\UserProfile\AppData\Local\Programs\Python\PythonXX\python.exe,并替换XX为当前版本和UserProfile为您的配置文件)
最重要的是: 因为您已设置新位置,请先安装setuptools,如果已经安装,则首先升级它。 然后,您可以将代码迁移到新的venv,所有新的软件包都应该可以正常工作,没有任何connectionResetErrors。

1
由于Windows中的SSLKEYLOGFILE环境变量(用于TLS解密)设置为无效路径会导致此问题,在Python中也会出现此错误,而其他软件将忽略缺少的文件。

你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Community

1

pip 20.3似乎存在问题: https://github.com/pypa/pip/issues/9190 我已经降级到20.2.4,这对我有用。

(我知道它不能成为原始问题的原因,但我认为当前也遇到该问题的人也会访问此页面)


0

如果在代理后问题仍然存在,您可以尝试使用此解决方案进行解决,例如:

conn.tls_in_tls_required = False
at \Lib\site-packages\pip\_vendor\urllib3\connectionpool.py

0

我用过这个,它是自动安装的。

python.exe -m pip install upgrade robotframework-seleniumlibrary --proxy="proxy:port

-2

这看起来像是最新的PIP问题。我拥有PIP v20和Python 3.7,一切都运行得很好。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接