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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM