我对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

当前回答

对我来说,创建一个文件夹就解决了这个问题 Pip,有一个文件:Pip .ini 在 C:\Users\ <用户名> \ AppData \ \徘徊 例句:

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

我在信里写道:

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

我重新启动python,然后pip永久信任这些站点,并使用它们下载包。

如果你在windows上找不到AppData文件夹,在文件资源管理器中写入% AppData %,它就会出现。

其他回答

在64位Windows 7企业版上尝试使用ActivePython 2.7.8、ActivePython 3.4.1和“库存”Python 3.4.2安装pip 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。

这个页面上的任何东西都不适合我,直到我使用——verbose选项看到它想要获得files.pythonhosted.org而不是pypi.python.org:

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

所以通过——verbose选项检查它失败的URL。

短期解决方案:

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

不要跳过!找到Linux的安全解决方案

所有使用——trusted-host将pypi.org添加到可信站点的解决方案都是不安全的,基本上跳过了https,并没有真正解决问题。 每个使用这种方法的人,请尝试以这种方式更新您的证书,并删除——trusted-host标志:

sudo yum -y update ca-certificates
export PIP_CERT=/etc/ssl/certs/ca-bundle.crt 

安全很重要!

只是把这个放在这里,因为我没有看到其他人提到它。

你可以像这样设置全局可信主机为pip:

py -m pip config set global.trusted-host pypi.org

最重要的是,它将返回放置pip.ini/pip.conf的正确位置