pip安装失败,出现“连接错误:[SSL:CERTIFICATE\u VERIFY\u FAILED]CERTIFICATE VERIFY FAILED(\u SSL.c:598)”

2024-06-16 11:15:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python很陌生,并试图在Windows 7上> pip install linkchecker。一些注释:

  • 无论软件包如何,pip安装都将失败。例如,> pip install scrapy也会导致SSL错误。
  • Python 3.4.1的普通安装包括pip 1.5.6。我试着做的第一件事就是安装linkchecker。Python2.7已经安装,它与ArcGIS一起提供。pythonpip在我安装3.4.1之前无法从命令行获得。
  • > pip search linkchecker有效。也许这是因为pip search没有验证站点的SSL证书。
  • 我在一个公司网络中,但我们不通过代理访问互联网。
  • 每个公司的计算机(包括我的计算机)都有一个受信任的根证书颁发机构,它用于各种原因,包括启用对https://google.com的TLS流量的监视。不确定这是否与此有关。

以下是运行pip install linkchecker后mypip.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

Tags: installpiphttpsorgpypiurlsslfor
3条回答

可以使用以下参数指定证书:

pip --cert /etc/ssl/certs/FOO_Root_CA.pem install linkchecker

见:Docs » Reference Guide » pip

如果指定公司的根证书不起作用,那么cURL证书可能会起作用:http://curl.haxx.se/ca/cacert.pem

必须使用PEM文件而不是CRT文件。如果你有一个CRT文件,你需要convert the file to PEM注释中有报告说现在可以使用CRT文件,但是我还没有验证。

还要检查:SSL Cert Verification

通过将^{}^{}设置为受信任主机,可以忽略SSL错误。

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

注意:在2018年4月的某个时候,Python Package Indexpypi.python.org迁移到pypi.org。这意味着使用旧域的“受信任主机”命令不再工作。

永久固定

由于pip 10.0的发布,您应该能够通过升级pip本身来永久地修复这个问题:

$ pip install --trusted-host pypi.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 <package_name>。请注意,某些包将找不到或会出现小错误。
  • 使用控制盘:下载Wheel of the python package,并使用pip命令pip install wheel_package_name.whl安装软件包。

kenorb’s answer非常有用(非常好!)。
在他的解决方案中,也许这是最简单的一个: --trusted-host

例如,在这种情况下,您可以

pip install --trusted-host pypi.python.org linkchecker

pem文件(或任何其他文件)是不必要的。

相关问题 更多 >