我经常做pip install <package-name>
在我的虚拟环境中的 Google Compute Engine (Debian) 上,但今天我只是收到了我尝试安装的任何包的新连接错误:
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x7f42a65bdf60>:
Failed to establish a new connection: [Errno 101] Network is unreachable',)':
/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl
我知道还有其他相关帖子建议指定代理,但我已经pip install
过去在同一台机器上多次访问,但不知何故今天它只是返回上述错误。看起来不像是代理问题。什么可以改变?
pip
版本是 10.0.1
并且该机器显然具有实时互联网连接(它是我们在 Google Compute Engine 上的产品服务器)。我可以从机器上成功 ping 网站。
最佳答案
由于 pip3 通过 HTTPS 运行,因此需要为 Google Compute Engine 实例上的传出流量(到特定 IP)打开端口 443
。
引用GCP docs有关如何执行此操作的详细说明(使用命令行或 GUI)。获取 files.pythonhosted.org
的 IP 以设置目标 IP。
(这个 helpful comment 指出了在 AWS EC2 实例上使用 pip3
的相同问题)
关于python - 在 debian 上 pip 安装失败并出现 NewConnectionError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50218268/