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

解决pip安装失败:SSL证书验证错误
在Windows 7上安装Python包时遇到pip SSL证书验证失败的问题。尝试使用http代替https,或者指定公司根证书,或者降级pip版本至1.2.1。另外,使用 可能能避免SSL错误,但不保证安全。如果问题依然存在,考虑设置个人PyPI服务器。
部署运行你感兴趣的模型镜像

本文翻译自:pip install fails with “connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)”

I am very new to Python and trying to > pip install linkchecker on Windows 7. Some notes: 我是Python的新手,并尝试> pip install linkchecker在Windows 7上> pip install linkchecker 。一些注意事项:

  • pip install is failing no matter the package. 无论软件包如何,pip安装都会失败。 For example, > pip install scrapy also results in the SSL error. 例如, > pip install scrapy也会导致SSL错误。
  • Vanilla install of Python 3.4.1 included pip 1.5.6. 原始安装的Python 3.4.1包含pip 1.5.6。 The first thing I tried to do was install linkchecker. 我尝试做的第一件事是安装linkchecker。 Python 2.7 was already installed, it came with ArcGIS. Python 2.7已经安装,它是ArcGIS附带的。 python and pip were not available from the command line until I installed 3.4.1. 在我安装3.4.1之前,无法从命令行使用pythonpip
  • > pip search linkchecker works. > pip search linkchecker起作用。 Perhaps that is because pip search does not verify the site's SSL certificate. 可能是因为点子搜索无法验证站点的SSL证书。
  • I am in a company network but we do not go through a proxy to reach the Internet. 我在公司网络中,但是我们没有通过代理访问Internet。
  • Each company computer (including mine) has a Trusted Root Certificate Authority that is used for various reasons including enabling monitoring TLS traffic to https://google.com . 每台公司计算机(包括我的计算机)都具有受信任的根证书颁发机构,出于各种原因使用该证书颁发机构,包括启用监视到https://google.com的 TLS流量。 Not sure if that has anything to do with it. 不确定是否与此有关。

Here are the contents of my pip.log after running pip install linkchecker : 这是运行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

#1楼

参考:https://stackoom.com/question/1l11j/pip安装失败-并显示-连接错误-SSL-CERTIFICATE-VERIFY-FAILED-证书验证失败-ssl-c


#2楼

You can specify a cert with this param: 您可以使用以下参数指定证书:

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

See: Docs » Reference Guide » pip 请参阅: 文档»参考指南»点

If specifying your company's root cert doesn't work maybe the cURL one will work: http://curl.haxx.se/ca/cacert.pem 如果指定您公司的根证书无效,则可能无法使用cURL: http : //curl.haxx.se/ca/cacert.pem

You must use a PEM file and not a CRT file. 您必须使用PEM文件而不是CRT文件。 If you have a CRT file you will need to convert the file to PEM There are reports in the comments that this now works with a CRT file but I have not verified. 如果您有CRT文件,则需要将其转换为PEM 。注释中有报告说,该报告现在可用于CRT文件,但我尚未验证。

Also check: SSL Cert Verification . 还要检查: SSL证书验证


#3楼

You can try to bypass the SSL error by using http instead of https. 您可以尝试使用http而不是https来绕过SSL错误。 Of course this is not optimal in terms of security , but if you are in a hurry it should do the trick: 当然,就安全性而言,并不是最佳选择 ,但是如果您急于赶快,那就可以采取以下措施:

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

#4楼

我通过删除我的点子并安装了较旧版本的点子来解决此问题: https : //pypi.python.org/pypi/pip/1.2.1


#5楼

Had the same problem trying pip install ftputil with ActivePython 2.7.8, ActivePython 3.4.1, and "stock" Python 3.4.2 on 64-bit Windows 7 Enterprise. 尝试在64位Windows 7 Enterprise上使用ActivePython 2.7.8,ActivePython 3.4.1和“ pip install ftputil ” Python 3.4.2 pip install ftputil相同的问题。 All attempts failed with the same errors as OP. 所有尝试均以与OP相同的错误失败。

Worked around the problem for Python 3.4.2 by downgrading to pip 1.2.1: easy_install pip==1.2.1 (see https://stackoverflow.com/a/16370731/234235 ). 通过降级为pip 1.2.1解决了Python 3.4.2的问题: easy_install pip==1.2.1 (请参阅https://stackoverflow.com/a/16370731/234235 )。 Same fix also worked for ActivePython 2.7.8. 同样的修复也适用于ActivePython 2.7.8。

The bug, reported in March 2013, is still open: https://github.com/pypa/pip/issues/829 . 该bug于2013年3月报告,目前仍在打开: https : //github.com/pypa/pip/issues/829


#6楼

I recently ran into this problem because of my company's web content filter that uses its own Certificate Authority so that it can filter SSL traffic. 我最近遇到了这个问题,因为我公司的Web内容过滤器使用自己的证书颁发机构,以便可以过滤SSL流量。 PIP doesn't seem to be using the system's CA certificates in my case, producing the error you mention. 在我的情况下,PIP似乎没有使用系统的CA证书,从而产生了您提到的错误。 Downgrading PIP to version 1.2.1 presented its own set of problems later on, so I went back to the original version that came with Python 3.4. 后来将PIP降级到1.2.1版会带来一系列问题,因此我回到了Python 3.4附带的原始版本。

My workaround is quite simple: use easy_install . 我的解决方法非常简单:使用easy_install Either it doesn't check the certs (like the old PIP version), or it knows to use the system certs because it works every time for me and I can still use PIP to uninstall packages installed with easy_install. 它要么不检查证书(例如旧的PIP版本),要么知道使用系统证书,因为它每次都对我有用,我仍然可以使用PIP卸载使用easy_install安装的软件包。

If that doesn't work and you can get access to a network or computer that doesn't have the issue, you could always setup your own personal PyPI server: how to create local own pypi repository index without mirror? 如果那行不通,并且您可以访问没有问题的网络或计算机,则可以始终设置自己的个人PyPI服务器: 如何在没有镜像的情况下创建本地自己的pypi存储库索引?

I almost did that until I tried using easy_install as a last ditch effort. 在尝试使用easy_install作为最后的努力之前,我几乎做到了。

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

### Anaconda Cloud API SSL证书验证错误的解决方法 在使用Anaconda Cloud API时,如果遇到SSL证书验证失败错误(`SSL certificate verify failed`),通常是因为系统无法找到或信任用于验证HTTPS连接的CA证书。以下是几种可能的解决方案: #### 1. **禁用SSL验证(不推荐用于生产环境)** 如果你处于一个受控环境中,且确定网络是安全的,可以临时禁用SSL验证。可以通过设置 `REQUESTS_CA_BUNDLE` 环境变量为空值来实现: ```bash set REQUESTS_CA_BUNDLE= ``` 或者,在代码中直接修改请求行为: ```python import requests response = requests.get('https://api.anaconda.org', verify=False) ``` 这种方式会忽略所有SSL证书验证,但不建议在生产环境中使用,因为它会使你的连接暴露于中间人攻击的风险中[^4]。 #### 2. **手动指定CA证书路径** 如果你的系统缺少默认的信任库,或者你想使用自定义的CA证书文件,可以手动下载指定CA证书路径。可以从 [certifi](https://pypi.org/project/certifi/) 获取最新的Mozilla CA证书包: ```bash pip install certifi ``` 安装完成后,将 `certifi` 提供的证书路径导出为环境变量: ```bash set REQUESTS_CA_BUNDLE=C:\path\to\cacert.pem ``` 其中 `C:\path\to\cacert.pem` 是 `certifi` 包中 `cacert.pem` 文件的实际路径。这样可以让 `requests` 库使用这个证书来进行SSL验证[^4]。 #### 3. **更新Conda和相关插件** 有时,Anaconda Cloud API的问题可能是由于Conda本身的版本过旧或某些插件损坏导致的。你可以尝试更新Conda到最新版本,重新安装相关的插件: ```bash conda update -n base -c defaults conda conda install anaconda-cloud-auth ``` 如果仍然存在问题,可以尝试清除Conda缓存重新安装相关插件: ```bash conda clean --all conda install --force-reinstall anaconda-cloud-auth ``` 这些操作可以帮助修复因Conda插件损坏而导致的SSL证书验证问题。 --- ### 查找适用于Win-32平台的Python 3.11*包 如果你需要查找适用于Win-32平台的Python 3.11版本的Conda包,可以使用以下几种方法: #### 1. **使用Conda命令行搜索** Conda自带了一个强大的搜索功能,可以直接通过命令行查询特定平台和Python版本的包: ```bash conda search --platform win-32 python=3.11* ``` 这条命令会列出所有支持Win-32平台且兼容Python 3.11的包。你可以根据输出结果选择你需要的包进行安装。 #### 2. **使用Anaconda Navigator界面** 如果你更喜欢图形化界面,可以打开Anaconda Navigator,进入“Environments”选项卡,然后点击“Search Packages”按钮。在搜索框中输入 `python=3.11` 确保平台设置为 Win-32,系统会自动筛选出符合条件的包[^1]。 #### 3. **访问Anaconda官方仓库网页** 你可以直接访问 [Anaconda官方仓库](https://anaconda.org/),在搜索栏中输入 `python=3.11`,然后在过滤器中选择 `win-32` 平台。这将显示所有支持该平台和Python版本的包。点击具体的包名后,页面会提供详细的安装命令,例如: ```bash conda install -c conda-forge some-package-name ``` #### 4. **使用第三方镜像源(如清华源)** 如果你在使用官方源时速度较慢,可以考虑切换到国内的镜像源,比如清华大学提供的镜像: ```bash conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --set show_channel_urls yes ``` 配置完成后,再次运行 `conda search --platform win-32 python=3.11*` 命令,应该可以获得更快的响应速度和更全面的结果[^1]。 ---
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值