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

当前回答

您可以尝试使用http而不是https来绕过SSL错误。当然,这在安全性方面并不是最优的,但如果你赶时间,它应该可以做到:

pip install --index-url=http://pypi.python.org/simple/ linkchecker

其他回答

为了一劳永逸地解决这个问题,您可以验证您有一个pip.conf文件。

根据文档,这是你的pip.conf应该在的地方:

在Unix上,默认的配置文件是:$HOME/.config/pip/pip.conf,它尊重XDG_CONFIG_HOME环境变量。 在macOS上,如果$HOME/Library/Application Support/pip目录存在,则配置文件为$HOME/.config/pip/pip.conf 在Windows上,配置文件是%APPDATA%\pip\pip.ini。

在virtualenv内部:

在Unix和macOS上,文件是$VIRTUAL_ENV/pip.conf 在Windows上,文件是:%VIRTUAL_ENV%\pip.ini

你的pip.conf应该是这样的:

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

pip install linkchecker在我创建pip.conf文件后安装linkchecker,没有抱怨。

我通过更改代理设置来自动检测代理设置来解决这个问题。

您可以通过以下方法解决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包装套接字对象-验证证书。

使用——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证书验证。

pip install gensim config --global http.sslVerify false

只需安装任何带有“config——global http. conf”的包。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包索引从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

或者重新安装以获得最新版本:

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

(…然后使用相关的Python解释器运行get-pip.py)。

PIP install <otherpackage>应该在此之后工作。如果没有,那么您将需要做更多的工作,如下所述。


您可能希望将受信任主机和代理添加到配置文件中。

pip.ini (Windows)或pip.conf (unix)

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

替代解决方案(不太安全)

大多数答案都可能带来安全问题。

有两个变通方法可以帮助您轻松安装大多数python包:

使用easy_install:如果您真的很懒,不想浪费太多时间,请使用easy_install <package_name>。注意,有些包找不到,或者会出现小错误。 使用Wheel:下载python包的Wheel,使用pip命令pip install wheel_package_name。WHL安装包。