【问题标题】:Unable to install any package through pip无法通过 pip 安装任何软件包
【发布时间】:2018-01-05 08:39:21
【问题描述】:

由于某种原因,我在使用 pip 安装新软件包时遇到问题。我有一个 OS Sierra 环境,之前一切正常。现在无论我是否使用 virtualenv,我都会得到:

Collecting requests
Could not find a version that satisfies the requirement requests (from 
  versions: )
No matching distribution found for requests

这不仅适用于“请求”库,还适用于所有其他库(例如 django 等)。

我有最新的点子:

 pip --version
 returns: pip 9.0.1 from /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)

而我的python版本是:2.7.12

此外,基于on this article,我检查了是否可以 curl PyPi 网站,并且确实收到了回复。

知道有什么问题吗?

已编辑

我执行 pip 安装为:

pip install -vvv requests

我得到了错误的详细输出:

Collecting requests
  2 location(s) to search for versions of requests:
  * http://pypi.python.org/simple/requests/
  * http://pypi.wfp.org/simple/requests/
  Getting page http://pypi.python.org/simple/requests/
  Starting new HTTP connection (1): pypi.python.org
  "GET /simple/requests/ HTTP/1.1" 403 16
  Could not fetch URL http://pypi.python.org/simple/requests/: 403 Client 
  Error: SSL is required for url: http://pypi.python.org/simple/requests/ - 
  skipping
  Getting page http://pypi.wfp.org/simple/requests/
  Starting new HTTP connection (1): pypi.wfp.org
  "GET /simple/requests/ HTTP/1.1" 404 None
  Could not fetch URL http://pypi.wfp.org/simple/requests/: 404 Client 
  Error: NOT FOUND for url: http://pypi.wfp.org/simple/requests/ - skipping
  Could not find a version that satisfies the requirement requests (from 
  versions: )
 Cleaning up...
  No matching distribution found for requests
 Exception information:
 Traceback (most recent call last):
 File "/Library/Python/2.7/site-packages/pip-9.0.1-
py2.7.egg/pip/basecommand.py", line 215, in main
  status = self.run(options, args)
 File "/Library/Python/2.7/site-packages/pip-9.0.1-
py2.7.egg/pip/commands/install.py", line 324, in run
requirement_set.prepare_files(finder)
File "/Library/Python/2.7/site-packages/pip-9.0.1-
py2.7.egg/pip/req/req_set.py", line 380, in prepare_files
ignore_dependencies=self.ignore_dependencies))
File "/Library/Python/2.7/site-packages/pip-9.0.1-
py2.7.egg/pip/req/req_set.py", line 554, in _prepare_file
require_hashes
File "/Library/Python/2.7/site-packages/pip-9.0.1-
py2.7.egg/pip/req/req_install.py", line 278, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/index.py", 
line 514, in find_requirement
'No matching distribution found for %s' % req
DistributionNotFound: No matching distribution found for requests

【问题讨论】:

  • requests doc 网站上写道:“Python 3 的使用比 Python 2 更受欢迎。如果您发现自己今天仍在生产中使用 Python 2,请考虑升级您的应用程序和基础架构. 如果你使用的是 Python 3,那么恭喜你——你确实是一个很有品味的人。——Kenneth Reitz”。
  • 你是如何运行pip的?
  • @vinzee opinion 并不意味着requests 与 Python 2.7 不兼容。
  • @Klaus D. 我一如既往地执行:pip install requests
  • 您的 HTTP 似乎有问题。您是否使用了代理?你能在浏览器中打开显示的网址(例如http://pypi.python.org/simple/requests/)吗?

标签: python pip


【解决方案1】:

user1919 提出的解决方案帮助我解决了在 lxc ubuntu 容器上安装 tox 的问题,因为默认的 pip 版本 8 无法识别正确的 url

我用过:

pip install -v tox -i https://pypi.python.org/simple/
....
....
....
Successfully installed filelock-3.0.10 pluggy-0.9.0 py-1.8.0 setuptools-40.8.0 toml-0.10.0 tox-3.7.0 virtualenv-16.4.3

【讨论】:

    【解决方案2】:

    感谢@Klaus D. 评论(建议在命令中添加:-v 标志),我发现 URL 为:

      http://pypi.python.org/simple/requests/ 
    

    需要改成

      https://pypi.python.org/simple/requests/  (with SSL).
    

    执行此命令效果很好:

    pip install -v requests -i https://pypi.python.org/simple/
    

    或者,您可以更改 pip.conf 文件,如答案之一here

    [global]
    timeout = 60
    index-url = https://pypi.python.org/simple
    

    【讨论】:

      【解决方案3】:

      可能值得一试 pip install --ignore-installed --no-cache-dir pip 获取未损坏的 pip 版本(请参阅 here 了解完整问题)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多