【问题标题】:Pip hangs on "collecting numpy"Pip 挂在“收集 numpy”上
【发布时间】:2019-07-08 07:33:39
【问题描述】:

尝试在 Windows 10 机器和 python 3.7.2 中安装 python 包。我正在使用以下命令:

pip install numpy

它永远挂起。我尝试使用以下方法获取更多信息:

pip -vvv install numpy

结果如下:

Collecting numpy
  1 location(s) to search for versions of numpy:
  * https://pypi.org/simple/numpy/
  Getting page https://pypi.org/simple/numpy/
  Looking up "https://pypi.org/simple/numpy/" in the cache
  Request header has "max_age" as 0, cache bypassed
  Starting new HTTPS connection (1): pypi.org:443
  https://pypi.org:443 "GET /simple/numpy/ HTTP/1.1" 304 0

我试图研究它,但找不到任何东西。我不敢相信只有这个包会通过 HTTPS,这就是它失败的原因?

【问题讨论】:

  • 你可以试试:a)pip download numpy, b)pip install numpy*.whl 吗?
  • 试试pip3 install numpy
  • @AlexYu pip download numpy 也挂在同一点
  • 您是否按照@GuilleC 的建议尝试了--no-cache-dir?你在防火墙下吗?如果你:a)安装pipenv b)pipenv install numpy 会变成什么?
  • 是的,--no-cache-dir 工作,如果我自己安装包,但如果我将它添加到像pip install -r req.txt 这样的命令中,numpy 只是要安装的包之一的依赖项。 .

标签: python python-3.x numpy pip


【解决方案1】:

你可以尝试添加:

--no-cache-dir

默认情况下,当发出任何 HTTP 请求时,pip 将首先检查其本地缓存,以确定它是否为该请求存储了未过期的合适响应。如果错误出现在该过程的那部分,跳过缓存检查应该可以解决问题。

详情见官方pip documentation

【讨论】:

  • 你能详细说明为什么它会有所作为吗?
  • Http 304 表示“未修改”。我没有查看 pip 的来源,但缓存中的包可能会阻止安装
  • 它可以工作,但它不适用于要安装的软件包文件。例如:pip install -r req.txt 有包 pandas,它有 numpy 作为依赖项。添加 --no-cache-dir 没有在那里工作,它仍然挂起,但是当我自己安装 numpy 时它工作了
【解决方案2】:

作为一种解决方法,您可以手动下载并安装numpy

转到此处并选择您要安装的版本的 .whl 文件: https://pypi.org/simple/numpy/

下载后,您可以手动安装 .whl:

pip install numpy-1.16.1-cp37-cp37m-win_amd64.whl

【讨论】:

    【解决方案3】:

    我对 Django 也有同样的问题。

    两个命令输出的差异如下:

    pip install Django -vvv
    ...
    Looking up "https://pypi.org/simple/django/" in the cache
    Request header has "max_age" as 0, cache bypassed
    https://pypi.org:443 "GET /simple/django/ HTTP/1.1" 304 0
    <hangs here>
    
    $ pip install Django --no-cache-dir -vvv
    ...
    https://pypi.org:443 "GET /simple/django/ HTTP/1.1" 200 27460
    <continues and successfully installs>
    

    使用--no-cache-dir 只是绕过了这个问题。

    当我手动删除缓存目录的内容时,解决方案来了。

    rm -Rf ~/.cache/pip/* 允许pip install Django 按预期工作,缓存又开始自我重建。

    docs,您可以根据您的操作系统找到缓存所在的路径:

    缓存目录的默认位置取决于操作 系统:

    Unix

    ~/.cache/pip and it respects the XDG_CACHE_HOME directory.

    macOS

    ~/Library/Caches/pip

    窗户

    &lt;CSIDL_LOCAL_APPDATA&gt;\pip\Cache

    【讨论】:

    • 没错,它只是绕过了问题。我还没有找到长期的解决方案
    • @Moseleyi 在我的情况下,当我删除缓存 rm -Rf ~/.cache/pip/* 时,pip install Django 在没有 --no-cache-dir 的情况下开始工作,并且缓存再次开始重建。
    • hm 但是如何实现自动化呢?我们有一个名为requirements 的文本文件,其中包含要安装的软件包列表。我不确定我可以在这样的脚本中加入这个吗?
    • @Moseleyi 哦,不,我手动做了一次。当缓存的内容与导致 pip 冻结挂起无法执行任何操作的内容一起被删除时,pip install -r requirements.txt 将“永远”按预期工作,无需修改,无需--no-cache-dir
    • @Moseleyi 还有帖子12在pip问题和SO暗示删除缓存是安全的。
    【解决方案4】:

    IPv6 不知何故为我造成了这个问题。在我的设备上禁用 ipv6 网络后,命令运行良好!

    【讨论】:

      猜你喜欢
      • 2017-08-20
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 2013-06-30
      • 2013-12-28
      • 1970-01-01
      相关资源
      最近更新 更多