Python “SSL证书验证失败”使用pip安装软件包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42509902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"SSL certificate verify failed" using pip to install packages
提问by imc
I am trying to install the Scrapy package (among others) for python using pip. I have tried doing the installation using python 3 and python 2, I have installed/upgraded the setuptools like so: $ pip3 install --upgrade setuptools
, I have tried to use the --trusted-host
option like so: $ pip3 install --trusted-host pypi.python.org Scrapy
. But I always get the same error message when I run $ pip3 install Scrapy
. The complete output is this:
我正在尝试使用 pip 为 python 安装 Scrapy 包(以及其他包)。我尝试使用 python 3 和 python 2 进行安装,我已经像这样安装/升级了 setuptools: $ pip3 install --upgrade setuptools
,我尝试使用这样的--trusted-host
选项:$ pip3 install --trusted-host pypi.python.org Scrapy
。但是我在运行时总是收到相同的错误消息$ pip3 install Scrapy
。完整的输出是这样的:
Collecting Scrapy
Using cached Scrapy-1.3.2-py2.py3-none-any.whl
Collecting PyDispatcher>=2.0.5 (from Scrapy)
Using cached PyDispatcher-2.0.5.tar.gz
Collecting service-identity (from Scrapy)
Using cached service_identity-16.0.0-py2.py3-none-any.whl
Collecting pyOpenSSL (from Scrapy)
Using cached pyOpenSSL-16.2.0-py2.py3-none-any.whl
Collecting w3lib>=1.15.0 (from Scrapy)
Using cached w3lib-1.17.0-py2.py3-none-any.whl
Collecting parsel>=1.1 (from Scrapy)
Using cached parsel-1.1.0-py2.py3-none-any.whl
Collecting queuelib (from Scrapy)
Using cached queuelib-1.4.2-py2.py3-none-any.whl
Requirement already satisfied: six>=1.5.2 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from Scrapy)
Collecting Twisted>=13.1.0 (from Scrapy)
Using cached Twisted-17.1.0.tar.bz2
Complete output from command python setup.py egg_info:
Download error on https://pypi.python.org/simple/incremental/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages may not be found!
Couldn't find index page for 'incremental' (maybe misspelled?)
Download error on https://pypi.python.org/simple/: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages may not be found!
No local packages or working download links found for incremental>=16.10.1
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/gy/5xt04_452z791v1qjs1yzxkh0000gn/T/pip-build-nkv4jozy/Twisted/setup.py", line 21, in <module>
setuptools.setup(**_setup["getSetupArgs"]())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/core.py", line 108, in setup
_setup_distribution = dist = klass(attrs)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 317, in __init__
self.fetch_build_eggs(attrs['setup_requires'])
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 372, in fetch_build_eggs
replace_conflicting=True,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 851, in resolve
dist = best[req.key] = env.best_match(req, ws, installer)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1123, in best_match
return self.obtain(req, installer)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1135, in obtain
return installer(requirement)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/dist.py", line 440, in fetch_build_egg
return cmd.easy_install(req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/setuptools/command/easy_install.py", line 668, in easy_install
raise DistutilsError(msg)
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('incremental>=16.10.1')
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/gy/5xt04_452z791v1qjs1yzxkh0000gn/T/pip-build-nkv4jozy/Twisted/
I am on a mac OS version 10.12.1 and am using python 3.6. Does anybody know a solution to this problem?
我在 Mac OS 版本 10.12.1 上使用 python 3.6。有人知道这个问题的解决方案吗?
采纳答案by imc
As stated here https://bugs.python.org/issue28150in previous versions of python Apple supplied the OpenSSL packages but does not anymore.
如此处所述https://bugs.python.org/issue28150在以前的 python 版本中 Apple 提供了 OpenSSL 包,但不再提供。
Running the command pip install certifi
and then pip install Scrapy
fixed it for me
运行命令pip install certifi
,然后pip install Scrapy
为我修复它
回答by Teja Swaroop
pip install --trusted-host pypi.python.org autopep8 (any package name)
pip install --trusted-host pypi.python.org autopep8 (any package name)
This command will add pypi.python.org
to the trusted sources and will install all the required package.
此命令将添加pypi.python.org
到受信任的源并将安装所有必需的包。
I ran into the error myself and typing this command helped me install all the pip packages of python.
我自己遇到了这个错误,输入这个命令帮助我安装了 python 的所有 pip 包。
回答by Greg
One note on the above answers: it is no longer sufficient to add just pypi.python.org to the trusted-hosts in the case where you are behind an HTTPS-intercepting proxy (we have zScaler).
关于上述答案的一个说明:在 HTTPS 拦截代理(我们有 zScaler)后面的情况下,仅将 pypi.python.org 添加到受信任主机已不再足够。
I currently have the following in my pip.ini:
我目前在 pip.ini 中有以下内容:
trusted-host = pypi.python.org pypi.org files.pythonhosted.org
Running pip -v install pkg
will give you some hints as to which hosts might need to be added.
运行pip -v install pkg
会给你一些关于可能需要添加哪些主机的提示。
回答by gbtimmon
Something to try --- tell python to not use https with the index directive and a http:// address (not https://)
可以尝试的东西 --- 告诉 python 不要将 https 与 index 指令和 http:// 地址(不是 https://)一起使用
pip install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org Scrapy
You may be behind a corporate firewall and Ive have experiences where even the above failed, though Im not going to pretend like I know enough about firewalls or SSL to understand why. In that case the only way I was able to get around that was to get a certificate file and pass it to python. See kenorb's answerhere for details.
您可能在公司防火墙后面,我有过即使上述方法也失败的经历,但我不会假装我对防火墙或 SSL 了解得足够了解原因。在那种情况下,我能够解决的唯一方法是获取证书文件并将其传递给 python。有关详细信息,请参阅此处kenorb 的回答。
回答by cowlinator
It seems that Scrapy
fails because installing Twisted
fails, which fails because incremental
fails. Running pip install --upgrade pip && pip install --upgrade incremental
fixed this for me.
似乎是Scrapy
因为安装Twisted
失败而失败,因为incremental
失败而失败。跑步pip install --upgrade pip && pip install --upgrade incremental
为我解决了这个问题。
回答by Reza Hashemi
In Windows 10 / search the drive you have installed the conda or it should be in C:\Users\name\AppData\Roaming\pipright with your mouse right click and select edit with notepad leave the [global] and replace what ever you have in there with blow code, Ctrl+s and rerun the code. it should work.
在 Windows 10 中/搜索您安装了 conda 的驱动器,或者它应该在 C:\Users\name\AppData\Roaming\pipright 用鼠标右键单击并选择用记事本编辑离开 [global] 并替换您所拥有的在那里使用打击代码,Ctrl + s 并重新运行代码。它应该工作。
trusted-host = pypi.python.org pypi.org files.pythonhosted.org
回答by rtl
pip3 install --trusted-host pypi.org --trusted-host files.pythonhosted.org <app>
回答by user2055509
If adding pypi.python.org as a trusted host does not work, you try adding files.pythonhosted.org. For example
如果将 pypi.python.org 添加为受信任的主机不起作用,您可以尝试添加 files.pythonhosted.org。例如
python -m pip install --upgrade --trusted-host files.pythonhosted.org <package-name>
回答by marw
You can try sudo apt-get upgrade
to get the latest packages. It fixed the issue on my machine.
您可以尝试sudo apt-get upgrade
获取最新的软件包。它解决了我机器上的问题。
回答by Chris Lope
It looks like they are also using pypi.org now. I added the following to %appdata%\pip\pip.ini and was able to download my packages from behind an HTTPS-intercepting proxy:
看起来他们现在也在使用 pypi.org。我将以下内容添加到 %appdata%\pip\pip.ini 并能够从 HTTPS 拦截代理后面下载我的包:
trusted-host = pypi.python.org files.pythonhosted.org pypi.org
trusted-host = pypi.python.org files.pythonhosted.org pypi.org