Python pip安装中“X的构建轮失败”是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/53204916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 20:15:50  来源:igfitidea点击:

What is the meaning of "Failed building wheel for X" in pip install?

pythonpython-3.xpippython-wheel

提问by not2qubit

This is a truly popular question here at SO, but none of the many answers I have looked at, clearly explain what this error really mean, and why it occurs.

这是 SO 上一个真正受欢迎的问题,但我看过的许多答案中没有一个能清楚地解释这个错误的真正含义以及它发生的原因。

One source of confusion, is that when (for example) you do pip install pycparser, you first get the error:

一个混乱的来源是,当(例如)你这样做时pip install pycparser,你首先得到错误:

Failed building wheel for pycparser

Failed building wheel for pycparser

which is then followed by the message that the package was:

然后是消息包是:

Successfully installed pycparser-2.19.

Successfully installed pycparser-2.19.



# pip3 install pycparser

Collecting pycparser
  Using cached https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz
Building wheels for collected packages: pycparser
  Running setup.py bdist_wheel for pycparser ... error
  Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-g_v28hpp/pycparser/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-__w_f6p0 --python-tag cp36:
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    ...
    File "/usr/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2349, in resolve
      module = __import__(self.module_name, fromlist=['__name__'], level=0)
  ModuleNotFoundError: No module named 'wheel.bdist_wheel'

  ----------------------------------------
  Failed building wheel for pycparser
  Running setup.py clean for pycparser
Failed to build pycparser
Installing collected packages: pycparser
  Running setup.py install for pycparser ... done
Successfully installed pycparser-2.19

What is going on here?

这里发生了什么?

(I would like to understand how something can fail but still get installed and whether you can trust this package functioning correctly?)

(我想了解某些东西是如何失败但仍然可以安装的,以及您是否可以相信这个包可以正常运行?)

So far the best partial explanation I have found is this.

到目前为止,我发现的最好的部分解释是这个

采纳答案by not2qubit

Since, nobody seem to mention this apart myself. My own solution to the above problem is most often to make sure to disable the cachedcopy by using: pip install <package> --no-cache-dir.

因为,除了我自己,似乎没有人提到这一点。我自己解决上述问题是最常见的,以确保禁用缓存使用副本:pip install <package> --no-cache-dir

回答by pradyunsg

(pip maintainer here!)

(点子维护者在这里!)

If the package is not a wheel, pip tries to build a wheel for it (via setup.py bdist_wheel). If that fails for any reason, you get the "Failed building wheel for pycparser" message and pip falls back to installing directly (via setup.py install).

如果包不是轮子,pip 会尝试为它构建一个轮子(通过setup.py bdist_wheel)。如果由于任何原因失败,您会收到“pycparser 的构建轮失败”消息,pip 回退到直接安装(通过setup.py install)。

Once we have a wheel, pip can install the wheel by unpacking it correctly. pip tries to install packages via wheels as often as it can. This is because of various advantages of using wheels (like faster installs, cache-able, not executing code again etc).

一旦我们有了一个轮子,pip 就可以通过正确地打开它来安装轮子。pip 尝试尽可能多地通过轮子安装软件包。这是因为使用轮子的各种优点(例如安装速度更快、可缓存、不再执行代码等)。



Your error message here is due to the wheelpackage being missing, which contains the logic required to build the wheels in setup.py bdist_wheel. (pip install wheelcan fix that.)

您在此处的错误消息是由于wheel缺少包,其中包含在setup.py bdist_wheel. (pip install wheel可以解决这个问题。)



The above is the legacy behavior that is currently the default; we'll switch to PEP 517 by default, sometime in the future, moving us to a standards-based process for this. We also have isolated builds for that so, you'd have wheel installed in those environments by default. :)

以上是当前默认的遗留行为;我们将默认切换到 PEP 517,在未来的某个时候,为此将我们转移到基于标准的流程。我们也有独立的构建,所以默认情况下你会在这些环境中安装轮子。:)

回答by Matthew Wai

Yesterday, I got the same error: Failed building wheel for hddfancontrolwhen I ran pip3 install hddfancontrol. The result was Failed to build hddfancontrol. The cause was error: invalid command 'bdist_wheel'and Running setup.py bdist_wheel for hddfancontrol ... error. The error was fixed by running the following:

昨天,我遇到了同样的错误: Failed building wheel for hddfancontrol当我运行pip3 install hddfancontrol. 结果是Failed to build hddfancontrol。原因是error: invalid command 'bdist_wheel'Running setup.py bdist_wheel for hddfancontrol ... error。通过运行以下命令修复了错误:

 pip3 install wheel

(From here.)

(从这里开始。)

Alternatively, the "wheel" can be downloaded directly from here. When downloaded, it can be installed by running the following:

或者,“轮子”可以直接从这里下载。下载后,可以通过运行以下命令进行安装:

pip3 install "/the/file_path/to/wheel-0.32.3-py2.py3-none-any.whl"

回答by SteveJ

It might be helpful to address this question from a package deployment perspective.

从包部署的角度解决这个问题可能会有所帮助。

There are many tutorials out there that explain how to publish a package to PyPi. Below are a couple I have used;

有很多教程解释了如何将包发布到 PyPi。下面是我用过的几个;

medium
real python

中等
真正的蟒蛇

My experience is that most of these tutorials only have you use the .tar of the source, not a wheel. Thus, when installing packages created using these tutorials, I've received the "Failed to build wheel" error.

我的经验是,这些教程中的大多数只让您使用源代码的 .tar,而不是轮子。因此,在安装使用这些教程创建的软件包时,我收到了“无法构建轮子”错误。

I later found the link on PyPi to the Python Software Foundation's docs PSF Docs. I discovered that their setup and build process is slightly different, and does indeed included building a wheel file.

后来我在 PyPi 上找到了 Python 软件基金会文档PSF Docs 的链接。我发现他们的设置和构建过程略有不同,并且确实包括构建轮文件。

After using the officially documented method, I no longer received the error when installing my packages.

使用官方记录的方法后,我在安装包时不再收到错误消息。

So, the error might simply be a matter of how the developer packaged and deployed the project. None of us were born knowing how to use PyPi, and if they happened upon the wrong tutorial -- well, you can fill in the blanks.

因此,错误可能只是开发人员如何打包和部署项目的问题。我们中没有人一出生就知道如何使用 PyPi,如果他们遇到错误的教程——好吧,你可以填写空白。

I'm sure that is not the only reason for the error, but I'm willing to bet that is a major reason for it.

我确信这不是错误的唯一原因,但我敢打赌这是造成错误的主要原因。

回答by t w

Try this:

尝试这个:

sudo apt-get install libpcap-dev libpq-dev

sudo apt-get install libpcap-dev libpq-dev

It has worked for me when I have installed these two.

当我安装这两个时,它对我有用。

See the link herefor more information

有关更多信息,请参阅此处的链接

回答by JanKanis

On Ubuntu 18.04, I ran into this issue because the aptpackage for wheeldoes not include the wheelcommand. I think pip tries to import the wheelpython package, and if that succeeds assumes that the wheelcommand is also available. Ubuntu breaks that assumption.

在 Ubuntu 18.04 上,我遇到了这个问题,因为aptfor的包wheel不包含wheel命令。我认为 pip 尝试导入wheelpython 包,如果成功则假设该wheel命令也可用。Ubuntu 打破了这个假设。

The apt python3 code package is named python3-wheel. This is installed automatically because python3-piprecommends it.

apt python3 代码包名为python3-wheel. 这是自动安装的,因为python3-pip推荐它。

The apt python3 wheel command package is named python-wheel-common. Installing this too fixes the "failed building wheel" errors for me.

apt python3 wheel 命令包名为python-wheel-common. 安装它也为我修复了“失败的构建轮”错误。

回答by Marc Guvenc

I got the same message when I tried to install pip install django-imagekit. So I ran pip install wheel (I had python 2.7) and then I reran pip install django-imagekit and it worked. Thanks

当我尝试安装 pip install django-imagekit 时,我收到了同样的消息。所以我运行了 pip install wheel(我有 python 2.7),然后我重新运行了 pip install django-imagekit 并且它工作了。谢谢

回答by Infallible wisdoms

This may Help you ! ....

这可能会帮助你!....

Uninstalling pycparser:

卸载pycparser:

pip uninstall pycparser

pip uninstall pycparser

Reinstall pycparser:

重新安装pycparser:

pip install pycparser

pip install pycparser

I got same error while installing termcolor and I fixed it by reinstalling it .

我在安装 termcolor 时遇到了同样的错误,我通过重新安装来修复它。