python - pip 安装失败,显示 "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)"

标签 python windows ssl pip

我是 Python 的新手,正在尝试在 Windows 7 上> pip install linkchecker。一些注意事项:

  • 无论包是什么,pip 安装都会失败。例如,> pip install scrapy 也会导致 SSL 错误。
  • Python 3.4.1 的普通安装包含 pip 1.5.6。我尝试做的第一件事是安装 linkchecker。 Python 2.7 已经安装,它随 ArcGIS 一起提供。在我安装 3.4.1 之前,pythonpip 在命令行中不可用。
  • > pip search linkchecker 有效。可能是因为 pip search 不验证站 pip 的 SSL 证书。
  • 我在公司网络中,但我们不通过代理访问 Internet。
  • 每台公司计算机(包括我的计算机)都有一个受信任的根证书颁发机构,用于各种原因,包括启用监控到 https://google.com 的 TLS 流量.不确定这是否与此有关。

运行 pip install linkchecker 后,我的 pip.log 的内容如下:

Downloading/unpacking linkchecker
  Getting page https://pypi.python.org/simple/linkchecker/
  Could not fetch URL https://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
  Will skip URL https://pypi.python.org/simple/linkchecker/ when looking for download links for linkchecker
  Getting page https://pypi.python.org/simple/
  Could not fetch URL https://pypi.python.org/simple/: connection error: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/ (Caused by <class 'http.client.CannotSendRequest'>: Request-sent)
  Will skip URL https://pypi.python.org/simple/ when looking for download links for linkchecker
  Cannot fetch index base URL https://pypi.python.org/simple/
  URLs to search for versions for linkchecker:
  * https://pypi.python.org/simple/linkchecker/
  Getting page https://pypi.python.org/simple/linkchecker/
  Could not fetch URL https://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
  Will skip URL https://pypi.python.org/simple/linkchecker/ when looking for download links for linkchecker
  Could not find any downloads that satisfy the requirement linkchecker
Cleaning up...
  Removing temporary dir C:\Users\jcook\AppData\Local\Temp\pip_build_jcook...
No distributions at all found for linkchecker
Exception information:
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:\Python34\lib\site-packages\pip\commands\install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "C:\Python34\lib\site-packages\pip\req.py", line 1177, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "C:\Python34\lib\site-packages\pip\index.py", line 277, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
pip.exceptions.DistributionNotFound: No distributions at all found for linkchecker

最佳答案

pip install gensim config --global http.sslVerify false

只需使用“config --global http.sslVerify false”语句安装任何包

您可以通过设置 pypi.org 来忽略 SSL 错误和 files.pythonhosted.org 以及旧的 pypi.python.org 作为受信任的主机。

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

注意:2018 年 4 月的某个时候,Python Package Index迁移自 pypi.python.orgpypi.org .这意味着使用旧域的“可信主机”命令不再有效,但您可以同时添加两者。

永久修复

自 pip 10.0 发布以来,您应该能够通过升级 pip 来永久修复此问题本身:

$ pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org pip setuptools

或者仅通过 reinstalling it获取最新版本:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

(……然后使用相关的 Python 解释器运行 get-pip.py)。

pip install <otherpackage>应该在这之后工作。如果没有,那么您将需要做更多的事情,如下所述。


您可能想要 add the trusted hosts and proxy to your config file .

pip.ini (Windows) 或 pip.conf (unix)

[global]
trusted-host = pypi.python.org
               pypi.org
               files.pythonhosted.org

替代解决方案(不太安全)

大多数答案可能会带来安全问题。

有助于轻松安装大多数 python 包的两个解决方法是:

  • 使用 easy_install:如果您真的很懒并且不想浪费太多时间,请使用 easy_install <package_name> .请注意,某些包将找不到或会出现小错误。
  • Using Wheel:下载 Wheel of the python package并使用 pip 命令 pip install wheel_package_name.whl安装包。

关于python - pip 安装失败,显示 "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51714885/

相关文章:

java - 签名证书在本地不受信任

java - 使用 .getLocations 确定元素在两个浏览器中的移动

python - 如何使用 Django 表单创建过滤下拉列表?

python - 从 GET 请求中得到错误的响应

windows - 如何在 IDA Pro 中获取 .text 段统计信息?

windows - 将剪贴板内容粘贴到命令提示符窗口的键盘快捷方式 (Win XP)

python - 如何在 SymPy 中将很小的数简化为 0?

c++ - 如果您在进程崩溃后为其分配内存会怎样?

ssl - 安装然后删除 SSL 证书 - 现在出现 fatal error : Call to a member function isLogged() on null

apache - 如何将特定链接重定向到 https ://everything else to http://using . htaccess?