安装 pip 失败,SSL 证书验证失败 (_ssl.c:833)。

10

我无法通过pip install安装任何外部Python模块,虽然我已经正确安装了Python,但在使用pip_install时,它显示了以下错误:

这是我运行pip install pytesseract后的代码:

 C:\Users\190560>pip install pytesseract
Collecting pytesseract
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),)': /simple/pytesseract/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),)': /simple/pytesseract/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),)': /simple/pytesseract/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),)': /simple/pytesseract/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),)': /simple/pytesseract/
  Could not fetch URL https://pypi.org/simple/pytesseract/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pytesseract/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),)) - skipping
  Could not find a version that satisfies the requirement pytesseract (from versions: )
No matching distribution found for pytesseract
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: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)'),)) - skipping

我该如何解决这个问题?

通过使用这个命令,我可以部分地解决这个问题。

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>

但是,我在电脑上找不到任何pip.ini文件夹,正如这里的问题所建议的那样。有什么建议可以永久解决这个问题吗?

@srj 我没有使用任何企业网络!! - Yash Soni
@abarnert 我正在使用Windows 10平台,并且我正在使用最新版本的Python,即Python 3.6.5。我是通过python.org安装程序安装的。我失败的唯一步骤是我上面提到的那个步骤,错误也已经指明了。 - Yash Soni
你是否执行了 pip install --trusted-host <etc.>-U pip setuptools 命令?在某些情况下,这是将临时/部分解决方案转化为永久修复的方法,这就是我要求你执行该命令的原因。 - abarnert
@dsgdfg 为什么你刚刚发布了一个链接到已经被链接过的同一个问题,并且OP已经在谈论它了呢? - abarnert
可能是重复的问题,参考无法安装Python包[SSL:TLSV1_ALERT_PROTOCOL_VERSION] - phd
显示剩余2条评论
4个回答

15

当我在企业网络中需要代理访问外部网络时,我也遇到了类似的问题。此时,我们需要告诉pip使用代理:

pip --proxy=http://your.corporate.proxy.com  install pytesseract

另一个可能的原因是由于pypi域名更改。在这种情况下,您可以尝试以下解决方案:

pip --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org install pytesseract

另一个类似的案例,有一个很好的答案:pip always fails ssl verification


我曾经在公司代理后面,这真的帮了我很多。谢谢! - Shailendra

1

曾经我为此问题苦苦挣扎了三天,什么都不起作用,然后我找到了这个解决方案。

可能的解决方案是指示Python使用您的Windows证书存储而不是certifi软件包中的内置存储。您可以通过安装python-certifi-win32来实现:

pip install python-certifi-win32

然后Python将使用与您的浏览器相同的证书。


请注意,此内容已更改为pip-system-certs。 - Emptyless

0

我曾经遇到过类似的问题,后来发现与网络IPv6地址有关。我不知道为什么会这样。解决我的问题的方法是禁用IPv6。你可以在这里(适用于Windows和MacOS X)找到如何禁用IPv6。


0
在 Windows 上,如果使用代理,请在“控制面板 - Internet 选项 - 连接 - LAN 设置”中暂时禁用它。
或者永久绕过代理(也可以在“LAN设置”中)以便于访问"pypi.org;files.pythonhosted.org"。

LAN settings - exceptions pypi.org;files.pythonhosted.org


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