我对 Python 非常陌生,并尝试在 Windows 7 上> pip install linkchecker
。一些注意事项:
无论软件包如何,pip install 都会失败。例如, > pip install scrapy 也会导致 SSL 错误。
Python 3.4.1 的香草安装包括 pip 1.5.6。我尝试做的第一件事是安装链接检查器。 Python 2.7 已经安装,它随 ArcGIS 一起提供。在我安装 3.4.1 之前,命令行中无法使用 python 和 pip。
> pip 搜索链接检查器有效。这可能是因为 pip search 没有验证站点的 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
sudo
时,会在 linux 中发生此问题。 (如果有人在linux中遇到这个问题)
pip install gensim config --global http.sslVerify false
只需使用“config --global http.sslVerify false”语句安装任何软件包
您可以通过将 pypi.org
和 files.pythonhosted.org
以及较旧的 pypi.python.org
设置为受信任的主机来忽略 SSL 错误。
$ 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.org
迁移到了 pypi.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
使用Wheel:下载python包的Wheel,使用pip命令pip install wheel_package_name.whl安装包。
您可以使用此参数指定证书:
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。
pip.conf
文件来永久引用它们而无需指定命令
对我来说,这个问题是通过创建一个文件夹 pip
来解决的,其中包含一个文件:C:\Users\<username>\AppData\Roaming\
中的 pip.ini
,例如:
C:\Users\<username>\AppData\Roaming\pip\pip.ini
我在里面写道:
[global]
trusted-host = pypi.python.org
pypi.org
files.pythonhosted.org
我重新启动了 python,然后 pip 永久信任这些站点,并使用它们从中下载包。
如果在 Windows 上找不到 AppData 文件夹,请在文件资源管理器中写入 %appdata%
,它应该会出现。
kenorb’s answer 非常有用(而且很棒!)。
在他的解决方案中,也许这是最简单的一个:--trusted-host
例如,在这种情况下你可以做
pip install --trusted-host pypi.python.org linkchecker
pem 文件(或其他任何文件)是不必要的。
pip list --trusted-host pypi.python.org --outdated
答案非常相似,有点令人困惑。就我而言,我公司网络中的证书是问题所在。我能够使用以下方法解决该问题:
pip install --trusted-host files.pythonhosted.org --trusted-host pypi.org --trusted-host pypi.python.org oauthlib -vvv
As seen here。如果不需要详细输出,可以省略 -vvv 参数
使用 Python 3.9 在 Windows 10 上与 Netscope 相关的 SSL 问题
由于与 netscope 相关的公司网络安全,我遇到了 ssl 问题。我的机器是带有 python 3.9 的 windows 10,以下命令对我有用。
pip config set global.trusted-host "pypi.org files.pythonhosted.org pypi.python.org" --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org
在这里,pip 永久信任这些站点,现在我们可以使用它们下载任何包。
永久修复
pip install --upgrade pip --trusted-host pypi.org --trusted-host files.pythonhosted.org
例如:
pip install <package name> --trusted-host pypi.org --trusted-host files.pythonhosted.org
我尝试了此答案博客中提供的大多数解决方案,但是 它们都不起作用,我在尝试安装 python 包时遇到了这个 ssl certificant error
。
我通过以下命令成功:
python -m pip install PACKAGENAME --trusted-host=pypi.python.org --trusted-host=pypi.org --trusted-host=files.pythonhosted.org
我发现的最直接的方法是在 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 文件的路径
(最后一行假设您使用的是 bash shell)在运行 pip 之前。
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。
要一劳永逸地解决此问题,您可以验证您是否拥有 pip.conf
文件。
根据 documentation,这是您的 pip.conf
所在的位置:
在 Unix 上,默认配置文件是:$HOME/.config/pip/pip.conf,它尊重 XDG_CONFIG_HOME 环境变量。在 macOS 上,如果目录 $HOME/Library/Application Support/pip 存在,则配置文件为 $HOME/Library/Application Support/pip/pip.conf 否则为 $HOME/.config/pip/pip.conf 在 Windows 上,配置文件为 % APPDATA%\pip\pip.ini。
在虚拟环境中:
在 Unix 和 macOS 上,文件为 $VIRTUAL_ENV/pip.conf 在 Windows 上,文件为:%VIRTUAL_ENV%\pip.ini
您的 pip.conf
应如下所示:
[global]
trusted-host = pypi.python.org
在我创建 pip.conf
文件后,pip install linkchecker
安装 linkchecker
时没有出现任何问题。
pip
用户指南似乎已更新。我更新了 macOS 的答案。它有帮助吗?
brew
安装了 python3,请确保您使用的是 pip3
并将 pip.conf
创建为 $HOME/.config/pip/pip.conf
。我为我工作。
您可以通过以下方式解决 CERTIFICATE_VERIFY_FAILED
的问题:
使用 HTTP 而不是 HTTPS(例如 --index-url=http://pypi.python.org/simple/)。
使用 --cert
运行 python -c "import ssl; print(ssl.get_default_verify_paths())" 来检查当前的(验证是否存在)。
OpenSSL 有一对环境(SSL_CERT_DIR、SSL_CERT_FILE),可用于指定不同的证书数据库PEP-476。
使用 --trusted-host
在 Python 中,对 requests.get 使用 verify=False(请参阅:SSL 证书验证)。
使用 --proxy
阅读更多内容:TLS/SSL wrapper for socket objects - Verifying certificates。
设置正确的时间和日期!
对我来说,我的日期和时间在 Raspberry Pi 上配置错误。结果是使用 https://files.pythonhosted.org/ 服务器的所有 SSL 和 HTTPS 连接都失败了。
像这样更新它:
sudo date -s "Wed Thu 23 11:12:00 GMT+1 2018"
sudo dpkg-reconfigure tzdata
或直接使用例如 Google 的时间:
参考:https://superuser.com/a/635024/935136
sudo date -s "$(curl -s --head http://google.com | grep ^Date: | sed 's/Date: //g')"
sudo dpkg-reconfigure tzdata
我最近遇到了这个问题,因为我公司的 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
作为最后的努力。
pip
将其与 --cert MyCompanyRootCA.crt
一起使用。
您可以尝试使用 http 而不是 https 来绕过 SSL 错误。当然,这在安全性方面并不是最佳的,但如果你赶时间,它应该可以解决问题:
pip install --index-url=http://pypi.python.org/simple/ linkchecker
Could not fetch URL http://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
TLDR:
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r requirements.txt -vvv
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <packageName> -vvv
因此,已经有 30 多个问题的答案,但在 2020 年 6 月(在锁定期间)对我没有任何帮助。所有这些都是在过去的不同时刻给出的。我会尽量让这个答案在未来的任何时候都有效。问题是,当 pip 安装包时,它会尝试与存储包的主机 URL 连接,并且在下载它时不信任该 URL。
我们有两种方法可以解决这个问题: 简单的和不安全的: 1. 检查 pip 是点击哪个 URL 来下载包。
pip install <packageName> -vvv
如果您仔细检查输出,您会看到它可能会转到某个 URL,例如 pypi.org 或者可能是 pypi.python.org。
如果是,只需在命令中添加受信任的主机选项,如下所示:
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <packageName> -vvv
或者如果您正在使用需求文件:
pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org -r requirements.txt -vvv
安全方式:
转到每个 URL 并下载他们的公共证书(只是谷歌如何下载),创建一个链,将其存储为 .pem 文件并运行以下命令:
pip --cert YourPemFile.pem install <packageName>
我使用 easy_install 安装了 pip 1.2.1 并升级到最新版本的 pip(当时为 6.0.7),它能够在我的情况下安装软件包。
easy_install pip==1.2.1
pip install --upgrade pip
使用的答案
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>
您可以使用详细标志找到这些。
您有 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
资源
https://pip.pypa.io/en/latest/user_guide/#configuration
首先,
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>
在 64 位 Windows 7 Enterprise 上使用 ActivePython 2.7.8、ActivePython 3.4.1 和“库存”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。
不要跳过!找到适用于 Linux 的安全解决方案
使用 --trusted-host
将 pypi.org
添加到受信任站点的所有解决方案都不安全,基本上跳过 https,并不能真正解决问题。
使用此方法的每个人,请尝试更新您的以这种方式认证并删除 --trusted-host
标志:
sudo yum -y update ca-certificates
export PIP_CERT=/etc/ssl/certs/ca-bundle.crt
安全事项!
我尝试使用公司代理,但失败了。
我正在使用 Python 3.6
。
pip.conf
文件丢失。
以下是解决问题的步骤:
安装证书包: -pip --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org install certifi 创建一个 pip.conf 文件,如下:
$ cd ~/.config
$ mkdir pip
$ cd pip
$ nano pip.conf
将以下内容添加到新创建的 .conf
文件中,然后保存。
[global]
trusted-host = pypi.python.org files.pythonhosted.org pypi.org pypi.io
一切都完成了,它开始工作了。
在我使用 --verbose 选项查看它想要访问 files.pythonhosted.org 而不是 pypi.python.org 之前,此页面上的任何内容都没有对我有用:
pip install --trusted-host files.pythonhosted.org <package_name>
因此,通过 --verbose 选项检查它实际上失败的 URL。
我不确定这是否相关,但我有一个类似的问题,通过将这些文件从 Anaconda3/Library/bin 复制到 Anaconda3/DLLs 得到解决:
libcrypto-1_1-x64.dll
libssl-1_1-x64.dll
简短的解决方案:
easy_install <package name>
例如:
easy_install pandas
替代解决方案:
pip install <package_name> --trusted-host pypi.org --trusted-host files.pythonhosted.org
例子:
pip install pandas --trusted-host pypi.org --trusted-host files.pythonhosted.org
最近我在 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”文件。编辑文件并写入 [global]trusted-host = pypi.python.org 保存并关闭文件。现在使用 pip/visual studio 安装它工作正常。
一种解决方案(对于 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
希望这对某人有帮助!
pip3.6 config set global.cert '/<path>/server.crt'
只是把它放在这里,因为我没有看到任何其他提及它。
您可以像这样将全局可信主机设置为 pip:
py -m pip config set global.trusted-host pypi.org
最重要的是,它将返回放置 pip.ini/pip.conf 的正确位置
对于 Python 3.10
添加/更新文件的内容
[global]
trusted-host = pypi.python.org
pypi.org
files.pythonhosted.org
文件位置
MacOS - $HOME/Library/Application Support/pip/pip.conf Unix - $HOME/.config/pip/pip.conf Windows - %APPDATA%\pip\pip.ini
我通过删除我的 pip 并安装旧版本的 pip 解决了这个问题:https://pypi.python.org/pypi/pip/1.2.1
include the essential parts of the answer here
,因为它是一个 二进制文件 的链接...?
不定期副业成功案例分享
pip install --trusted-host pypi.python.org pypi_package
。使用--verbose
表明,如果没有--trusted-host
,HTTPS 连接将失败,而使用--trusted-host
尝试相同的 HTTPS 连接(不是 HTTP)但它成功。pip install --trusted-host pypi.python.org pythonPackage