我对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 install --trusted-host pypi.python.org <package name>

对我没用。我一直得到CERTIFICATE_VERIFY_FAILED错误。然而,我在错误消息中注意到他们引用了“pypi.org”站点。因此,我使用this作为可信主机名,而不是pypi.python.org。这句话几乎把我带到了那里;使用CERTIFICATE_VERIFY_FAILED加载仍然失败,但在稍后的时间点。找到了失败的网站的引用,我把它作为一个可信任的主机。最终对我有用的是:

    pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package name>

我也遇到过类似的问题。对我有效的解决方法 1)卸载python 2.7 2)删除python27文件夹 3)重新安装最新的python

使用——cert参数:

您可以使用以下命令指定证书:

pip --cert <path/to/cert>.pem install <package list>

例如:

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

参见:文档»参考指南»pip

如果指定您公司的根证书不起作用,也许cURL证书可以工作:http://curl.haxx.se/ca/cacert.pem

必须使用PEM文件,而不是CRT文件。如果你有一个CRT文件,你将需要将文件转换为PEM。评论中有报告说,这现在与CRT文件一起工作,但我还没有验证。

还要检查:SSL证书验证。

您可以通过以下方法解决CERTIFICATE_VERIFY_FAILED问题:

Use HTTP instead of HTTPS (e.g. --index-url=http://pypi.python.org/simple/). Use --cert <trusted.pem> or CA_BUNDLE variable to specify alternative CA bundle. E.g. you can go to failing URL from web-browser and import root certificate into your system. Run python -c "import ssl; print(ssl.get_default_verify_paths())" to check the current one (validate if exists). OpenSSL has a pair of environments (SSL_CERT_DIR, SSL_CERT_FILE) which can be used to specify different certificate databasePEP-476. Use --trusted-host <hostname> to mark the host as trusted. In Python use verify=False for requests.get (see: SSL Cert Verification). Use --proxy <proxy> to avoid certificate checks.

阅读更多:TLS/SSL包装套接字对象-验证证书。

我得到了同样的错误,即使尝试了许多黑客。 所以我去了官方网站(https://pypi.org/project/),在那里我们可以找到特定软件包的车轮文件(.whl)并下载了它。

现在在命令提示符中:

PIP安装path_to_wheel_file/file_name.whl

现在文件已经成功安装。