PIP install package SSLError

问题

使用pip安装package:

$ pip install <package>

报错:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': xxx/yyy
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': xxx/yyy
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': xxx/yyy
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': xxx/yyy
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)'))': xxx/yyy
Could not fetch URL https://pypi.org/xxx/yyy : There was a problem confirming the ssl certificate: … (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1125)')))

原因

PIP版本太高。降低 pip 版本可以解决问题。
我的 pip 版本是21.0.1,报错。降级为 20.2.3,问题解决。
(备注:我尝试过折腾 SSL,然而没用)

解决方法

我的python是在conda环境中的,可以按如下方法降级 pip:
$ conda install pip==20.2.3
需要确认是否降级:

The following packages will be DOWNGRADED:

  pip                                 21.0.1-py38h06a4308_0 --> 20.2.3-py38h06a4308_0

Proceed ([y]/n)? 

输入 y 再回车即可。

如果是直接用系统环境中的python,可以这样:
python -m pip install pip==20.2.3

降级完成后,再用pip install <package>就可以正常安装了。

参考资料

https://v2as.com/article/9ac87b61-b9d2-4f2a-9198-87f183cf0ea1

posted @ 2021-05-06 11:07  星夜之夏  阅读(952)  评论(0编辑  收藏  举报