Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
744 views
in Technique[技术] by (71.8m points)

python - pip安装失败,并显示“连接错误:[SSL:CERTIFICATE_VERIFY_FAILED]证书验证失败(_ssl.c:598)”(pip install fails with “connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)”)

I am very new to Python and trying to > pip install linkchecker on Windows 7. Some notes:

(我是Python的新手,并尝试> pip install linkchecker在Windows 7上> pip install linkchecker 。一些注意事项:)

  • pip install is failing no matter the package.

    (无论软件包如何,pip安装都会失败。)

    For example, > pip install scrapy also results in the SSL error.

    (例如, > pip install scrapy也会导致SSL错误。)

  • Vanilla install of Python 3.4.1 included pip 1.5.6.

    (原始安装的Python 3.4.1包含pip 1.5.6。)

    The first thing I tried to do was install linkchecker.

    (我尝试做的第一件事是安装linkchecker。)

    Python 2.7 was already installed, it came with ArcGIS.

    (Python 2.7已经安装,它是ArcGIS附带的。)

    python and pip were not available from the command line until I installed 3.4.1.

    (在我安装3.4.1之前,无法从命令行使用pythonpip 。)

  • > pip search linkchecker works.

    (> pip search linkchecker起作用。)

    Perhaps that is because pip search does not verify the site's SSL certificate.

    (可能是因为点子搜索无法验证站点的SSL证书。)

  • I am in a company network but we do not go through a proxy to reach the Internet.

    (我在公司网络中,但是我们没有通过代理访问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 .

    (每台公司计算机(包括我的计算机)都具有受信任的根证书颁发机构,出于各种原因使用该证书颁发机构,包括启用监视到https://google.com的 TLS流量。)

    Not sure if that has anything to do with it.

    (不确定是否与此有关。)

Here are the contents of my pip.log after running pip install linkchecker :

(这是运行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:UsersjcookAppDataLocalTemppip_build_jcook...
No distributions at all found for linkchecker
Exception information:
Traceback (most recent call last):
  File "C:Python34libsite-packagespipasecommand.py", line 122, in main
    status = self.run(options, args)
  File "C:Python34libsite-packagespipcommandsinstall.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "C:Python34libsite-packagespip
eq.py", line 1177, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "C:Python34libsite-packagespipindex.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
  ask by Jeremy Cook translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can ignore SSL errors by setting pypi.org and files.pythonhosted.org as trusted hosts.

(您可以通过将pypi.orgfiles.pythonhosted.org设置为可信主机来忽略SSL错误。)

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

Note : Sometime during April 2018, the Python Package Index was migrated from pypi.python.org to pypi.org .

(注意 :在2018年4月的某个时候, Python软件包索引已从pypi.python.org迁移到pypi.org 。)

This means "trusted-host" commands using the old domain no longer work.

(这意味着使用旧域的“受信任主机”命令不再起作用。)

Permanent Fix (永久修复)

Since the release of pip 10.0, you should be able to fix this permanently just by upgrading pip itself:

(从pip 10.0版本发布以来,您应该能够仅通过升级pip本身来永久修复此问题:)

$ pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools

Or by just reinstalling it to get the latest version:

(或者通过重新安装以获得最新版本:)

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

(… and then running get-pip.py with the relevant Python interpreter).

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

pip install <otherpackage> should just work after this.

(pip install <otherpackage>应该在此之后工作。)

If not, then you will need to do more, as explained below.

(如果没有,那么您将需要做更多的事情,如下所述。)


You may want to add the trusted hosts and proxy to your config file .

(您可能需要将信任的主机和代理添加到配置文件中 。)

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

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

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

Alternate Solutions (Less secure)

(替代解决方案(安全程度较低))

Most of the answers could pose a security issue.

(大多数答案可能会带来安全问题。)

Two of the workarounds that help in installing most of the python packages with ease would be:

(有助于轻松安装大多数python软件包的两种解决方法是:)

  • Using easy_install : if you are really lazy and don't want to waste much time, use easy_install <package_name> .

    (使用easy_install :如果您真的很懒,不想浪费很多时间,请使用easy_install <package_name> 。)

    Note that some packages won't be found or will give small errors.

    (请注意,找不到某些软件包,或者会产生一些小错误。)

  • Using Wheel : download the Wheel of the python package and use the pip command pip install wheel_package_name.whl to install the package.

    (使用Wheel :下载python软件包Wheel并使用pip命令pip install wheel_package_name.whl安装该软件包。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...