由于 SSL 错误无法使用 pip 安装 Python 库。

3

我已经为此苦苦挣扎了相当长的时间,基本上无法使用pip。我看到的其他帖子似乎都不适用于我的情况。非常感谢任何人可以给我帮助。

系统正在运行Centos 7

Python是通过以root身份运行的yum安装的。

>python3.6 -m pip --trusted-host=pypi.org --trusted-host=pypi.python.org install flask
Defaulting to user installation because normal site-packages is not writeable
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:877)'),)': /simple/flask/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:877)'),)': /simple/flask/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:877)'),)': /simple/flask/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:877)'),)': /simple/flask/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:877)'),)': /simple/flask/
Could not fetch URL https://pypi.org/simple/flask/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/flask/ (Caused by SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:877)'),)) - skipping
ERROR: Could not find a version that satisfies the requirement flask
ERROR: No matching distribution found for flask
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:877)'),)) - skipping

我确认了 pip 已经是最新版本:

>python3.6 -m pip --version
pip 21.0.1 from /home/user/.local/lib/python3.6/site-packages/pip (python 3.6)

并且在yum中安装了openssl

Package 1:openssl-devel-1.0.2k-21.el7_9.x86_64 already installed and latest version

Python可使用SSL:

python3.6 -m ssl

谢谢!

编辑:旧版本的PIP似乎至少可以正常下载它


也许你可以在这里找到答案:https://dev59.com/lGQo5IYBdhLWcg3wDLpj - e.arbitrio
不行...我已经查看了该线程中的每个解决方案,但它们都是针对不同的问题。 - mr odus
1个回答

0

今天我遇到了完全相同的错误,我的情况是因为Python无法处理服务器上设置的HTTP代理环境变量。似乎Python试图与HTTP端口(:80)建立TCP握手,但显然失败了。

幸运的是,在我的情况下,我能够在没有代理的情况下访问pypi.org,这解决了我的问题:

http_proxy= https_proxy= sudo pip3.8 install [PKGNAME]

如果这对您不起作用,请仔细检查您是否获得了所有各种环境变量:
env | grep -i proxy

例如,它们可能在您的系统上以全部大写字母形式编写(HTTP_PROXY/HTTPS_PROXY),或者您可能已经设置了ALL_PROXY/all_proxy

如果仍然不起作用,您可能无法在没有代理的情况下访问pypi,所以您需要找出如何使它起作用。


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