【问题标题】:When does "pip install" build a wheel?“pip install”什么时候造轮子?
【发布时间】:2016-05-12 05:03:29
【问题描述】:

我发现在不同的文件夹中,有时pip install 会构建轮子,这需要花费很多时间,而有时则不会。我不确定为什么以及如何控制它。

我的命令:bin/python -m pip install -r ../requirements.txt(由于!# shebang line-length限制,所以我不直接使用pip)

不造轮子的输出(只需要几秒钟):

Collecting numpy==1.10.4 (from -r ../requirements.txt (line 1))
Installing collected packages: numpy
Successfully installed numpy-1.10.4

构建轮的输出(至少需要 2 分钟)

Collecting numpy==1.10.4 (from -r ../requirements.txt (line 1))
  Downloading numpy-1.10.4.tar.gz (4.1MB)
    100% |████████████████████████████████| 4.1MB 92kB/s
Building wheels for collected packages: numpy
  Running setup.py bdist_wheel for numpy ... done
  Stored in directory: /root/.cache/pip/wheels/66/f5/d7/f6ddd78b61037fcb51a3e32c9cd276e292343cdd62d5384efd
Successfully built numpy
Installing collected packages: numpy
Successfully installed numpy-1.10.4

requirements.txt的内容:

numpy==1.10.4

【问题讨论】:

    标签: python pip


    【解决方案1】:

    这取决于您的包是纯 python 包(无需编译任何东西,只需将文件复制到某处)还是包含 c 源代码的包(在这种情况下需要编译并调用编译器并执行,这需要更长的时间)。

    http://pythonwheels.com/

    您可能还想看一下车轮文档:

    http://wheel.readthedocs.org/en/latest/

    【讨论】:

    • numpy是否是一个纯python包会描述是否会导致python构建轮子,但这并不能解释为什么有时它会构建轮子正如问题所示,有时它不会。
    【解决方案2】:

    我得到了答案,这只是第一次构建轮子,之后它将从缓存中读取

    【讨论】:

      【解决方案3】:

      今天我遇到了一个包没有正确安装的问题,因为它的构建过程会生成不正确的轮子包,即使直接安装也可以。

      我做了一些探索,结果发现截至目前 (pip == 8.1.2),没有直接的方法来控制 pip 是否会尝试从给定的包裹。我找到了relevant source code,显然,当且仅当:

      • wheel 模块是可导入的
      • 缓存目录正在使用中

      由于该逻辑,可以通过在安装命令行上传递 --no-cache-dir 来间接禁用 pip 对基于轮的构建的使用。

      【讨论】:

      • 看起来这个逻辑已经发生了很大变化(现在在pip==19)。代码现在可以追溯到github.com/pypa/pip/blob/…。不幸的是,似乎没有一个方便的标志来关闭轮子构建功能(除了卸载轮子),同时为已经带有轮子的软件包保留轮子安装。
      • 其实你可以通过设置--no-binary={package_name}来明确哪些包不应该生成轮子...
      • Pip 也有 --only-binary--prefer-binary 参数。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-18
      • 2017-02-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多