首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >pip安装失败,并显示“连接错误:[SSL: CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:598)”。

pip安装失败,并显示“连接错误:[SSL: CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:598)”。
EN

Stack Overflow用户
提问于 2014-09-23 03:25:20
回答 49查看 1.2M关注 0票数 532

我是Python的新手,正在尝试在Windows7上使用> pip install linkchecker

无论软件包是什么,

  • pip安装都会失败。例如,> pip install scrapy也会导致SSL错误。Python3.4.1的
  • Vanilla install包含pip 1.5.6。我尝试做的第一件事就是安装链接检查器。Python2.7已经安装好了,它附带了ArcGIS。在我安装3.4.1.
  • > pip search linkchecker works之前,无法从命令行使用pythonpip。也许这是因为pip搜索不会在公司网络中验证站点的SSL am,但我们不会通过代理来访问Internet.
  • Each公司的计算机(包括我的计算机)具有受信任的根证书颁发机构,该机构用于各种原因,包括启用对https://google.com流量的监控。我不确定这是否与此有关。

以下是运行pip install linkchecker后我的pip.log的内容

代码语言:javascript
运行
复制
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
EN

回答 49

Stack Overflow用户

发布于 2015-04-20 23:13:41

代码语言:javascript
运行
复制
pip install gensim config --global http.sslVerify false

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

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

代码语言:javascript
运行
复制
$ pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <package_name>

注意:在2018年4月的某个时候,Python Package Indexpypi.python.org迁移到了pypi.org。这意味着使用旧域的"trusted-host“命令不再有效,但您可以同时添加这两个命令。

永久修复

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

代码语言:javascript
运行
复制
$ pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org pip setuptools

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

代码语言:javascript
运行
复制
$ 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)

代码语言:javascript
运行
复制
[global]
trusted-host = pypi.python.org
               pypi.org
               files.pythonhosted.org

备用解决方案(安全性较低)

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

帮助轻松安装大多数python包的两种解决方法是:

  • Using easy_install:如果你真的很懒,不想浪费太多时间,那就使用easy_install <package_name>。请注意,有些软件包将找不到或会给出small errors.
  • Using Wheel:下载Wheel of the python package并使用pip命令pip install wheel_package_name.whl安装软件包。
票数 863
EN

Stack Overflow用户

发布于 2014-09-26 22:59:53

您可以使用此参数指定证书:

代码语言:javascript
运行
复制
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文件,你将需要 ,在评论中有报告说这现在与CRT文件一起工作,但我还没有验证。

还可以检查:SSL Cert Verification

票数 152
EN

Stack Overflow用户

发布于 2018-08-24 22:24:08

对我来说,这个问题是通过创建一个文件夹pip来修复的,在C:\Users\<username>\AppData\Roaming\中包含一个文件:pip.ini。例如:

代码语言:javascript
运行
复制
C:\Users\<username>\AppData\Roaming\pip\pip.ini

我在里面写道:

代码语言:javascript
运行
复制
[global]
trusted-host = pypi.python.org
               pypi.org
               files.pythonhosted.org

我重新启动了python,然后pip永久信任这些站点,并使用它们从下载包。

如果你在windows上找不到AppData文件夹,在文件资源管理器中输入%appdata%,它就会出现。

票数 100
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25981703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档