我对Python非常陌生,并试图在Windows 7上安装链接检查器。一些注意事项:

pip install is failing no matter the package. For example, > pip install scrapy also results in the SSL error. Vanilla install of Python 3.4.1 included pip 1.5.6. The first thing I tried to do was install linkchecker. Python 2.7 was already installed, it came with ArcGIS. python and pip were not available from the command line until I installed 3.4.1. > pip search linkchecker works. Perhaps that is because pip search does not verify the site's SSL certificate. I am in a company network but we do not go through a proxy to reach the 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. Not sure if that has anything to do with it.

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

当前回答

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. 检查哪个URL被pip击中下载包。

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>

其他回答

在连接中设置代理,然后运行:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py --proxy proxy:80

简短的回答

如果在家里使用公司的机器时遇到这种情况,在工作时再试一次。

细节

我周末遇到了这个。Pip和conda都坏了,无法安装或更新。SO很有帮助,但在公司机器上,许多答案都有问题——解决方案需要pip install(已经不能工作)或需要下载安装程序(我想下载的安装程序被防火墙设置禁止)。

对我有效的是当我上预科的时候再试一次。这很有效。事实证明,在家庭和工作中使用这台机器时,公司防火墙的设置是不同的。

我使用easy_install安装了pip 1.2.1,并升级到pip的最新版本(当时是6.0.7),该版本能够在我的情况下安装包。

easy_install pip==1.2.1
pip install --upgrade pip

最近我在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要求的版本(from versions:) 没有为numpy找到匹配的分布

解决方法:

Windows操作系统

open -> "%appdata%"如果不存在,创建pip文件夹。 在pip文件夹中创建“pip.ini”文件。 编辑文件并写入 (全球) trusted.host = pypi.python.org 保存并关闭文件。现在安装 使用pip/visual studio可以很好地工作。

要使用的答案

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>

您可以使用verbose标志找到这些。