首页 文章

pip install失败,出现“连接错误:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:598)”

提问于
浏览
244

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

无论包装是什么

  • pip install都失败了 . 例如, > pip install scrapy 也会导致SSL错误 .

  • 包含pip 1.5.6的Python 3.4.1的Vanilla安装 . 我尝试做的第一件事是安装linkchecker . Python 2.7已经安装,它随ArcGIS一起提供 . 在安装3.4.1之前,命令行中没有 pythonpip .

  • > pip search linkchecker 有效 . 也许这是因为pip搜索不会验证网站的SSL证书 .

  • 我在公司网络中,但我们没有通过代理来访问互联网 .

  • 每台公司计算机(包括我的)都有一个受信任的根证书颁发机构,由于各种原因使用,包括启用监控TLS流量到https://google.com . 不确定这与它有什么关系 .

以下是运行 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

30 回答

  • 0

    如果您使用 make 手动安装了Python,则必须遵循以下答案:https://stackoverflow.com/a/42798679/6403406才能使其正常工作 .

  • 58

    您可以通过将pypi.orgfiles.pythonhosted.org设置为可信主机来忽略SSL错误 .

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

    Note :在2018年4月的某个时间,Python Package Index已从 pypi.python.org 迁移到 pypi.org . 这意味着使用旧域的"trusted-host"命令不再起作用 .

    永久修复

    自从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
    

    Alternate Solutions (Less secure)

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

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

    • Using easy_install :如果你真的很懒,不想浪费太多时间,请使用 easy_install <package_name> . 请注意,找不到某些包或会出现小错误 .

    • Using Wheel :下载Wheel of the python package并使用pip命令 pip install wheel_package_name.whl 安装软件包 .

  • 8

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

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

    见:Docs » Reference Guide » pip

    如果指定您的公司's root cert doesn'工作可能cURL将工作:http://curl.haxx.se/ca/cacert.pem

    You must use a PEM file and not a CRT file. If you have a CRT file you will need to convert the file to PEM

    另请检查:SSL Cert Verification .

  • 4

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

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

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

    pem文件(或其他任何内容)是不必要的 .

  • 0

    我找到的最直接的方法是从https://www.digicert.com/digicert-root-certificates.htm#roots下载并使用DigiCert的"DigiCert High Assurance EV Root CA"

    您可以通过单击地址栏中的锁定图标来访问https://pypi.python.org/以验证证书颁发者,或使用openssl增加您的极客信誉:

    $ openssl s_client -connect pypi.python.org:443
    CONNECTED(00000003)
    depth=1 /C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA
    verify error:num=20:unable to get local issuer certificate
    verify return:0
    ---
    Certificate chain
     0 s:/businessCategory=Private Organization/1.3.6.1.4.1.311.60.2.1.3=US/1.3.6.1.4.1.311.60.2.1.2=Delaware/serialNumber=3359300/street=16 Allen Rd/postalCode=03894-4801/C=US/ST=NH/L=Wolfeboro,/O=Python Software Foundation/CN=www.python.org
       i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA
     1 s:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert SHA2 Extended Validation Server CA
       i:/C=US/O=DigiCert Inc/OU=www.digicert.com/CN=DigiCert High Assurance EV Root CA
    

    证书链中的最后一个CN值是您需要下载的CA的名称 .

    要进行一次性工作,请执行以下操作:

    • 从DigiCert下载CRT

    • 将CRT转换为PEM格式

    • 将PIP_CERT环境变量导出到PEM文件的路径

    (在运行pip之前,最后一行假定您使用的是bash shell) .

    curl -sO http://cacerts.digicert.com/DigiCertHighAssuranceEVRootCA.crt 
    openssl x509 -inform DES -in DigiCertHighAssuranceEVRootCA.crt -out DigiCertHighAssuranceEVRootCA.pem -text
    export PIP_CERT=`pwd`/DigiCertHighAssuranceEVRootCA.pem
    

    为了使其可重复使用,将DigiCertHighAssuranceEVRootCA.crt置于常用位置,并在〜/ .bashrc中相应地导出PIP_CERT .

  • -3

    答案非常相似,有点令人困惑 . 就我而言,我公司网络中的证书就是问题所在 . 我能够使用以下方法解决问题:

    pip install --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org oauthlib -vvv
    

    As seen here . 如果不需要详细输出,则可以省略-vvv参数

  • 18

    在我的情况下,我发现安装相关软件包时pip失败了 . 在我的情况下,python-heatclient需要位置,这需要pbr . pbr的安装失败了 . 当我在安装python-heatclient之前显式安装pbr时,它按预期工作 .

    呼叫失败 venv/bin/pip install python-heatclient

    呼叫成功

    venv/bin/pip install pbr

    venv/bin/pip install python-heatclient

  • 3

    您有以下可能性来解决 CERTIFICATE_VERIFY_FAILED 的问题:

    • 使用HTTP而不是HTTPS .

    • 使用 --cert <trusted.pem>CA_BUNDLE 变量指定备用CA捆绑包 .

    例如 . 您可以从Web浏览器转到失败的URL并将根证书导入您的系统 .

    • 运行 python -c "import ssl; print(ssl.get_default_verify_paths())" 以检查当前的(验证是否存在) .

    • OpenSSL有一对环境( SSL_CERT_DIRSSL_CERT_FILE ),可用于指定不同的证书databasePEP-476 .

    • 使用 --trusted-host <hostname> 将主机标记为受信任 .

    • 在Python中使用 verify=False 表示 requests.get (参见:SSL Cert Verification) .

    • 使用 --proxy <proxy> 以避免证书检查 .

    阅读更多:TLS/SSL wrapper for socket objects - Verifying certificates .

  • 9

    要一劳永逸地解决此问题,您可以验证您是否有 pip.conf 文件 .

    根据documentation,这是你的 pip.conf 应该是的地方:

    在Unix上,默认配置文件是:$ HOME / .config / pip / pip.conf,它尊重XDG_CONFIG_HOME环境变量 . 在macOS上配置文件是$ HOME / Library / Application Support / pip / pip.conf如果目录$ HOME / Library / Application Support / pip存在其他$ HOME / .config / pip / pip.conf在Windows上配置文件是% APPDATA%\ PIP \ pip.ini .

    Inside a virtualenv:

    在Unix和macOS上,文件是$ VIRTUAL_ENV / pip.conf在Windows上,文件是:%VIRTUAL_ENV%\ pip.ini

    你的 pip.conf 应该是这样的:

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

    pip install linkchecker 在创建 pip.conf 文件后没有抱怨 linkchecker .

  • 1

    您可以尝试使用http而不是https来绕过SSL错误 . 当然这是 not optimal in terms of security ,但是如果你赶时间应该这样做:

    pip install --index-url=http://pypi.python.org/simple/ linkchecker
    
  • 5

    我最近遇到了这个问题,因为我公司的Web内容过滤器使用自己的证书颁发机构,因此它可以过滤SSL流量 . 在我的情况下,PIP似乎没有使用系统的CA证书,产生您提到的错误 . 将PIP降级到版本1.2.1后面会出现一系列问题,所以我回到了Python 3.4附带的原始版本 .

    我的解决方法很简单:使用 easy_install . 要么它不检查证书(如旧的PIP版本),要么它知道使用系统证书,因为它每次都适用于我,我仍然可以使用PIP卸载使用easy_install安装的软件包 .

    如果没有问题,您可以随时设置自己的个人PyPI服务器:how to create local own pypi repository index without mirror?

    我几乎这样做,直到我尝试使用 easy_install 作为最后的努力 .

  • 1

    我使用easy_install安装了pip 1.2.1并升级到最新版本的pip(当时为6.0.7),它可以在我的情况下安装软件包 .

    easy_install pip==1.2.1
    pip install --upgrade pip
    
  • 0

    为了克服ssl验证问题,

    这是我尝试和工作的东西 . 当我尝试安装ansible时遇到错误,所以我把ansible放在包名中 .

    这告诉pip要信任我们下载的主机pypi.python.org并信任我们的软件包 .

    pip install --trusted-host pypi.python.org ansible pip install --trusted-host pypi.python.org --upgrade pip

  • 2

    首先,

    pip install --trusted-host pypi.python.org <package name>
    

    对我不起作用 . 我一直收到CERTIFICATE_VERIFY_FAILED错误 . 但是,我在错误消息中注意到他们引用了'pypi.org'网站 . 所以,我使用它作为可信主机名而不是pypi.python.org . 那几乎让我在那里;使用CERTIFICATE_VERIFY_FAILED,负载仍然失败,但稍后 . 找到对失败的网站的引用,我将其作为可信主机包含在内 . 最终对我有用的是:

    pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package name>
    
  • 4

    设置时间和日期正确!

    Mabey我回答得有点迟了

    对我来说,我的日期和时间在Raspberry Pi上配置错误 . 结果是使用https://files.pythonhosted.org/服务器,所有SSL和HTTPS连接都失败了 .

    像这样更新它:

    sudo date -s "Wed Aug  23 11:12:00 GMT+1 2018"
        dpkg-reconfigure tzdata
    
  • 385

    在64位Windows 7企业版上使用ActivePython 2.7.8,ActivePython 3.4.1和"stock" Python 3.4.2尝试 pip install ftputil 时遇到同样的问题 . 所有尝试都失败,出现与OP相同的错误 .

    通过降级到pip 1.2.1来解决Python 3.4.2的问题: easy_install pip==1.2.1 (参见https://stackoverflow.com/a/16370731/234235) . 同样的修复也适用于ActivePython 2.7.8 .

    2013年3月报道的这个漏洞仍然是开放的:https://github.com/pypa/pip/issues/829 .

  • 4

    使用的答案

    pip install --trusted-host pypi.python.org <package>
    

    工作 . 但你必须检查是否有重定向或缓存 pip 正在击中 . 在带有 pip 9.0.1 的Windows 7上,我必须运行

    pip install \
      --trusted-host pypi.python.org \
      --trusted-host pypi.org \
      --trusted-host files.pythonhosted.org \
      <package>
    

    您可以使用详细标记找到这些 .

  • 1

    你有4个选择:

    使用证书作为参数

    $ pip install --cert /path/to/mycertificate.crt linkchecker
    

    在pip.conf中使用证书

    创建此文件:

    $HOME/.pip/pip.conf (Linux)
    
    %HOME%\pip\pip.ini (Windows)
    

    并添加以下行:

    [global]
    cert = /path/to/mycertificate.crt
    

    忽略证书并使用HTTP

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

    忽略证书并在pip.conf中使用HTTP

    创建此文件:

    $HOME/.pip/pip.conf (Linux)
    
    %HOME%\pip\pip.ini (Windows)
    

    并添加以下行:

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

    来源

  • 81

    在我使用--verbose选项查看它想要访问files.pythonhosted.org而不是pypi.python.org之前,此页面上的任何内容都不适用于我:

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

    因此,请通过--verbose选项检查其实际失败的URL .

  • 7

    我通过删除我的点和安装旧版本的pip来解决这个问题:https://pypi.python.org/pypi/pip/1.2.1

  • 0

    您可以尝试忽略“https”:

    pip install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org  [your package..]
    
  • 1

    对我来说这是因为以前我正在运行脚本设置代理(到fiddler),重新打开控制台或重新启动修复问题 .

  • 19

    最近我在使用visual studio 2015的python 3.6中遇到了同样的问题 . 花了2天后,我得到了解决方案,它对我来说很好 .

    我尝试使用pip或从visual studio安装numpy时出现以下错误收集numpy无法获取URL https://pypi.python.org/simple/numpy/:确认ssl证书时出现问题:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:748) - 跳过可能找不到满足要求numpy的版本(来自版本:)没有为numpy找到匹配的发行版

    解析度 :

    对于Windows操作系统

    • open - > "%appdata%"创建"pip"文件夹(如果不存在) .

    • 在pip文件夹中创建"pip.ini"文件 .

    • 编辑文件并写入
      [全球]
      trusted-host = pypi.python.org保存并关闭文件 . 现在使用pip / visual studio安装它工作正常 .

  • 0

    Vaulstein回答帮助了我 .

    我没找到pip.ini文件在我的电脑上的任何地方 . 以下是如此 .

    • 去了AppData文件夹 . 您可以通过打开命令提示符并输入echo%AppData%来获取appdata文件夹

    AppData location using command prompt

    或者只需在Windows资源管理器中键入%AppData%即可 .

    AppData location in windows explorer

    • 在该appdata文件夹中创建一个名为pip的文件夹 .

    • 在刚刚创建的pip文件夹中,创建一个名为pip.ini的简单文本文件

    • 使用您选择的简单编辑器过去该文件中的以下配置设置 .

    pip.ini file:

    [list]
    format=columns
    
    [global]
    trusted-host = pypi.python.org pypi.org
    

    你现在应该好好去 .

  • 16

    一种解决方案(对于Windows)是在 %AppData%\pip\ 文件夹上创建名为 pip.ini 的文件(如果该文件夹不存在则创建该文件夹)并插入以下详细信息:

    [global]
    cert = C:/certs/python_root.pem
    proxy = http://my_user@my_company.com:my_password@proxy_ip:proxy_port
    

    ...然后我们可以执行安装指令:

    pip3 install PyQt5
    

    另一种选择是使用代理和证书的参数来安装包...

    $ pip3 install --proxy http://my_user@my_company.com:my_password@proxy_ip:proxy_port \
       --cert C:/certs/python_root.pem PyQt5
    

    要将证书 *.cer 文件转换为所需的 *.pem 格式,请执行以下指令:

    $ openssl x509 -inform der -in python_root.cer -out python_root.pem
    

    希望这有助于某人!

  • 7

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

    C:\Users\<username>\AppData\Roaming\pip\pip.ini
    

    在里面我写道:

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

    我重新启动了python,然后pip永久信任这些网站 .

  • 5

    对我来说,没有一种建议的方法可行 - 使用cert,HTTP,trusted-host .

    在我的情况下切换到不同版本的包工作(paho-mqtt 1.3.1而不是paho-mqtt 1.3.0在这个例子中) .

    看起来问题特定于该软件包版本 .

  • 16

    就我而言,我在最小的高山码头图像中运行Python . 它缺少根CA证书 . 固定:

    apk update && apk add ca-certificates

  • 2

    如果您的system.eg中缺少某些证书,则openuse install ca-certificates-mozilla可能会出现此问题

  • 1

    截至目前,当pip升级到10时,现在他们已经将路径从pypi.python.org更改为files.pythonhosted.org请将命令更新为pip --trusted-host files.pythonhosted.org install python_package

相关问题