Pip:无法为 pypi 获取 URL 并发出确认 ssl 证书的问题

Pip: Could not fetch URL for pypi and issue confirming the ssl certificate

我最近刚安装了 python(3.6.1),它是 运行 pip(9.0.1),每当我尝试安装一个包时,我都会收到以下错误:

pip install cx_Oracle

Collecting cx_Oracle
  Could not fetch URL https://pypi.python.org/simple/cx-oracle/: There was a pro
blem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificat
e verify failed (_ssl.c:749) - skipping
  Could not find a version that satisfies the requirement cx_Oracle (from versio
ns: )
No matching distribution found for cx_Oracle

由于证书有问题,我尝试这样做:

pip install --trusted-host pypi.python.org pytest-xdist

Collecting pytest-xdist
  Downloading pytest-xdist-1.15.0.tar.gz (87kB)
    100% |████████████████████████████████| 92kB 1.8MB/s
    Complete output from command python setup.py egg_info:
    Download error on https://pypi.python.org/simple/setuptools_scm/: [SSL: CERT
IFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages m
ay not be found!
    Download error on https://pypi.python.org/simple/setuptools-scm/: [SSL: CERT
IFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages m
ay not be found!
    Couldn't find index page for 'setuptools_scm' (maybe misspelled?)
    Download error on https://pypi.python.org/simple/: [SSL: CERTIFICATE_VERIFY_
FAILED] certificate verify failed (_ssl.c:749) -- Some packages may not be found
!
    No local packages or working download links found for setuptools_scm
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\ALEX~1.CAU\AppData\Local\Temp\pip-build-7vo4jump\pytest-xdi
st\setup.py", line 37, in <module>
        'Programming Language :: Python :: 3',
      File "c:\users\alex.cauthen\appdata\local\programs\python\python36\lib\dis
tutils\core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "c:\users\alex.cauthen\appdata\local\programs\python\python36\lib\sit
e-packages\setuptools\dist.py", line 315, in __init__
        self.fetch_build_eggs(attrs['setup_requires'])
      File "c:\users\alex.cauthen\appdata\local\programs\python\python36\lib\sit
e-packages\setuptools\dist.py", line 361, in fetch_build_eggs
        replace_conflicting=True,
      File "c:\users\alex.cauthen\appdata\local\programs\python\python36\lib\sit
e-packages\pkg_resources\__init__.py", line 850, in resolve
        dist = best[req.key] = env.best_match(req, ws, installer)
      File "c:\users\alex.cauthen\appdata\local\programs\python\python36\lib\sit
e-packages\pkg_resources\__init__.py", line 1122, in best_match
        return self.obtain(req, installer)
      File "c:\users\alex.cauthen\appdata\local\programs\python\python36\lib\sit
e-packages\pkg_resources\__init__.py", line 1134, in obtain
        return installer(requirement)
      File "c:\users\alex.cauthen\appdata\local\programs\python\python36\lib\sit
e-packages\setuptools\dist.py", line 429, in fetch_build_egg
        return cmd.easy_install(req)
      File "c:\users\alex.cauthen\appdata\local\programs\python\python36\lib\sit
e-packages\setuptools\command\easy_install.py", line 659, in easy_install
        raise DistutilsError(msg)
    distutils.errors.DistutilsError: Could not find suitable distribution for Re
quirement.parse('setuptools_scm')

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\ALEX~1.C
AU\AppData\Local\Temp\pip-build-7vo4jump\pytest-xdist\

收到 egg_info 错误后,我尝试了以下操作:

easy_install -U setuptools

Searching for setuptools
Reading https://pypi.python.org/simple/setuptools/
Download error on https://pypi.python.org/simple/setuptools/: [SSL: CERTIFICATE_
VERIFY_FAILED] certificate verify failed (_ssl.c:749) -- Some packages may not b
e found!
Couldn't retrieve index page for 'setuptools'
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [SSL: CERTIFICATE_VERIFY_FAIL
ED] certificate verify failed (_ssl.c:749) -- Some packages may not be found!
Best match: setuptools 28.8.0
Adding setuptools 28.8.0 to easy-install.pth file
Installing easy_install-script.py script to c:\users\alex.cauthen\appdata\local\
programs\python\python36\Scripts
Installing easy_install.exe script to c:\users\alex.cauthen\appdata\local\progra
ms\python\python36\Scripts
error: [WinError 5] Access is denied: 'c:\users\alex.cauthen\appdata\local\
programs\python\python36\Scripts\easy_install.exe'

许多类似 Whosebug 问题的答案都建议更改代理设置。我没有在代理后面工作,但我在 VPN 后面工作。我在安装软件包时遇到了与 NodeJS/react/npm 非常相似的问题,所有建议都是更改您的代理设置。我最终通过删除存储代理设置的文件解决了这个问题。

我找不到为 python/pip 提供相同功能的文件,想知道是否有人知道它在 Windows 7 上的位置?我也很想听听有关如何解决这个非常令人沮丧的问题的其他建议!!

亚历克斯

我的解决办法是先做pip install --trusted-host pypi.python.org setuptools_scm,然后再安装pytest-xdist

--trusted-host pypi.python.org 选项适用于我的所有要求,但 pytest-xdist 除外,正如您举的例子。提示是这个特定的包抱怨

Couldn't find index page for 'setuptools_scm' (maybe misspelled?)

不是您所问问题的完整答案,但您的输出与我刚刚处理的类似,所以这些是我的笔记。

在带有 python2.7 的 Mac 上,我有一个类似的 pip 安装错误抱怨 "There was a problem confirming the ssl certificate"。这是一个不同的包,但对我来说解决方案可能对其他人有用。我没有及时更新我家人使用的旧Mac。一旦我更新了自制软件,升级了我们已经安装的 brew 包,并使用 brew 重新链接,问题就解决了 python2.

brew update
brew upgrade
brew install python2
brew link --overwrite python@2