“pip install”何时会生成wheel文件?

29

我发现在不同的文件夹中,有时候运行pip install会构建wheel,这需要很长时间,有时则不会。我不确定为什么以及如何控制这个过程。

我的命令:bin/python -m pip install -r ../requirements.txt(由于!#的限制导致行长过长,所以我没有直接使用pip)

输出结果没有构建wheel(只需要几秒钟):

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
4个回答

23

今天我遇到了一个问题,因为发现构建过程生成了不正确的wheel包,即使直接安装是完全没有问题的,所以一个包没有被正确地安装。

我进行了一些探索,发现目前(pip == 8.1.2),没有一种直接的方法来控制pip是否尝试从特定的包中构建wheel。我找到了相关源代码,显然,只有在以下情况下才会使用wheel构建过程:

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

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


2
看起来这个逻辑已经有了很大的改变(现在是“pip==19”)。代码现在可以追踪到https://github.com/pypa/pip/blob/cf722df4f9d7f8ee2d62e53ef2354ea65e932170/src/pip/_internal/wheel_builder.py#L48。不幸的是,似乎没有方便的标志可以关闭轮构建功能(除了卸载wheel),同时保留已经安装了wheel的软件包的wheel安装。 - pelson
5
实际上,你可以通过设置“--no-binary = {package_name}”来明确指定不应生成wheels的软件包。 - pelson
1
Pip 还具有 --only-binary--prefer-binary 参数。 - cowlinator

10
这取决于你的软件包是否是纯 Python 软件包(无需编译任何内容,只需将文件复制到某个地方)或包含 C 源代码的软件包(在这种情况下需要编译,并调用和执行编译器,这需要更长的时间)。

http://pythonwheels.com/

你可能也想看看wheel文档:

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


13
“numpy” 是否是一个纯 Python 包描述了它是否会使 Python 构建 wheel,但这并不能解释为什么有时会构建 wheel,有时不会,正如问题所示。 - Cory Klein

5

我知道答案了,那只是第一次创建轮子,之后它将从缓存中读取。


0

当我在我的 Mac 上使用 pip3 安装 slither-analyzer 时,我遇到了类似的错误。

Building wheels for collected packages: pysha3
  Building wheel for pysha3 (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
   exit code: 1
  ╰─> [16 lines of output]

解决方案是重新安装您的Xcode工具。

$ xcode-select --install
$ xcode-select --reset

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接