【问题标题】:In Python 3, pip cannot install modules在 Python 3 中,pip 无法安装模块
【发布时间】:2018-01-16 09:53:48
【问题描述】:

我在尝试使用 pip 安装模块时遇到 SSL 错误,我在网上四处查看并找到了该问题的常见解决方案:

C:\Python35> pip3 install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org sphinx

但是,运行此命令并没有像我想象的那样工作。我做错了什么?

C:\Python35> pip3 install --index-url=http://pypi.python.org/simple/ --trusted-host pypi.python.org -vvv sphinx
Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
Collecting sphinx
  1 location(s) to search for versions of sphinx:
  * http://pypi.python.org/simple/sphinx/
  Getting page http://pypi.python.org/simple/sphinx/
  Starting new HTTP connection (1): pypi.python.org
  "GET /simple/sphinx/ HTTP/1.1" 403 16
  Could not fetch URL http://pypi.python.org/simple/sphinx/: 403 Client Error: SSL is required for url: http://pypi.python.org/simple/sphinx/ - skipping
  Could not find a version that satisfies the requirement sphinx (from versions: )
Cleaning up...
No matching distribution found for sphinx
Exception information:
Traceback (most recent call last):
  File "C:\python35\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\python35\lib\site-packages\pip\commands\install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "C:\python35\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\python35\lib\site-packages\pip\req\req_set.py", line 554, in _prepare_file
    require_hashes
  File "C:\python35\lib\site-packages\pip\req\req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "C:\python35\lib\site-packages\pip\index.py", line 514, in find_requirement
    'No matching distribution found for %s' % req
pip.exceptions.DistributionNotFound: No matching distribution found for sphinx

正如 Mukul Sharma 所写,使用

C:\Python35>pip3 install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.python.org -vvv sphinx

反而解决了我的问题。

【问题讨论】:

  • 尝试升级 pip pip install --upgrade pip 或使用此pip install packagename=version --allow-unverified packagename,因为某些包包含未经验证的文件。
  • C:\Python35>pip3 install --upgrade --index-url=pypi.python.org/simple --trusted-host pypi.python.org pip3 收集 pip3 找不到满足 pip3 要求的版本(来自版本:)没有为 pip3 找到匹配的分布
  • 使用这个pip3 install --upgrade pip
  • C:\Python35>pip3 install --upgrade pip3 正在收集 pip3 无法获取 URL pypi.python.org/simple/pip3:确认 ssl 证书时出现问题:[SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败 (_ssl.c :719) - 跳过找不到满足 pip3 要求的版本(来自版本:)没有找到 pip3 的匹配分布
  • pip3 install --upgrade pip 仍然给我 [SSL: CERTIFICATE_VERIFY_FAILED] 错误,但它也告诉我我的 pip 是最新的

标签: python-3.x pip python-sphinx


【解决方案1】:

Python 已停止支持使用 HTTP 的请求。他们只允许通过 HTTPS 的请求。你可以阅读更多关于它的信息here

这里只使用 https 而不是 http

C:\Python35> pip3 install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.python.org sphinx

【讨论】:

  • @Ephreal 我的意思是将我的答案标记为“答案”,如果它有效,也会发布原因
  • @Ephreal 完成。您可能也想检查原因
  • Python?你是说网站 python.org 吗?
猜你喜欢
  • 1970-01-01
  • 2016-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多