【问题标题】:unable to make a python3 wheel because bdist_wheel is an invalid command无法制作 python3 轮,因为 bdist_wheel 是无效命令
【发布时间】:2022-01-24 06:31:24
【问题描述】:

注意:解决方案是使用以下命令更新我的车轮版本:

pip install -U pip wheel setuptools

原来的问题

我正在尝试在python3中制作一个轮子,所以我按照这个教程进行操作:
https://medium.com/swlh/beginners-guide-to-create-python-wheel-7d45f8350a94

但是,当我运行命令 python3 setup.py bdist_wheel 时,我得到了这个错误:

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'bdist_wheel'

然后我检查了堆栈溢出的这个答案:
How to fix `error: invalid command 'bdist_wheel'`?

并尝试像这样重新安装轮子:pip3 install wheel,但是我收到了这条消息:

DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: wheel in /usr/local/lib/python3.9/site-packages (0.37.0)

我尝试再次运行python3 setup.py bdist_wheel,但它仍然给出相同的错误,所以我检查了页面:https://github.com/Homebrew/homebrew-core/issues/76621 上面的消息推荐给我,但是它告诉我没有什么可以做的时间:

If you have been directed here from a pip warning, you don't need to take any action at this stage. Nothing is currently expected to break until Python 3.12, and a full solution will be implemented well before then.

此时,我不确定下一步该去哪里解决我的问题。需要明确的是,我的目标是制作一个 python3 轮子。目前,我特别想为 PyPDF4 制作一个轮子:https://github.com/claird/PyPDF4,但我更希望能够为任何包制作轮子,而我遇到的问题似乎没有任何关系有了这个特定的包,所以这些额外的信息应该是不必要的。

如果这是相关的,我在 macos monterey 12.0.1

关于 venv:
我用这个命令创建了一个 virtualenv:virtualenv .,然后用source bin/activate 激活它。然后我运行python3 setup.py bdist_wheel 以查看是否可以使用教程中建议的原始命令,但是,我再次遇到了与本文顶部给出的相同错误。所以在我看来,制作 venv 并不能解决问题。

将轮子安装到 venv 中

这是我在构建轮子之前尝试将轮子安装到虚拟环境中的结果。如下所示,它也不起作用

➜  test2 git:(master) git pull https://github.com/claird/PyPDF4
remote: Enumerating objects: 2516, done.
remote: Total 2516 (delta 0), reused 0 (delta 0), pack-reused 2516
Receiving objects: 100% (2516/2516), 3.56 MiB | 1.75 MiB/s, done.
Resolving deltas: 100% (1661/1661), done.
From https://github.com/claird/PyPDF4
 * branch            HEAD       -> FETCH_HEAD
➜  test2 git:(master) virtualenv .
created virtual environment CPython3.9.9.final.0-64 in 323ms
  creator CPython3Posix(dest=/Users/.../test2, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/.../virtualenv)
    added seed packages: pip==21.3.1, setuptools==59.2.0, wheel==0.37.0
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
➜  test2 git:(master) ✗ source bin/activate
(test2) ➜  test2 git:(master) ✗ pip install wheel
Requirement already satisfied: wheel in ./lib/python3.9/site-packages (0.37.0)
(test2) ➜  test2 git:(master) ✗ pip3 install wheel
Requirement already satisfied: wheel in ./lib/python3.9/site-packages (0.37.0)
(test2) ➜  test2 git:(master) ✗ python3 setup.py bdist_wheel
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'bdist_wheel'
(test2) ➜  test2 git:(master) ✗

小笔记

@Pavel Hamerník,感谢您迄今为止的所有帮助。如果您厌倦了处理这个问题,请直接说出来,我会按原样接受您的回答。我已经成功地完成了制作轮子的目标,所以在这一点上,我只是为了在 stackoverflow 上发表更完整的帖子。如果你和我一样觉得这是值得的,那么我们应该继续努力找出问题所在。再次感谢

更新到最新版本

我跑了pip3 install -U pip wheel setuptools 并收到了这条消息:

DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: pip in /usr/local/lib/python3.9/site-packages (21.3.1)
Requirement already satisfied: wheel in /usr/local/lib/python3.9/site-packages (0.37.0)
Collecting wheel
  Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Requirement already satisfied: setuptools in /usr/local/lib/python3.9/site-packages (59.0.1)
Collecting setuptools
  Downloading setuptools-60.1.0-py3-none-any.whl (952 kB)
     |████████████████████████████████| 952 kB 7.3 MB/s
Installing collected packages: wheel, setuptools
  Attempting uninstall: wheel
    Found existing installation: wheel 0.37.0
    Uninstalling wheel-0.37.0:
      Successfully uninstalled wheel-0.37.0
  Attempting uninstall: setuptools
    Found existing installation: setuptools 59.0.1
    Uninstalling setuptools-59.0.1:
      Successfully uninstalled setuptools-59.0.1
  DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
awsebcli 3.19.4 requires six<1.15.0,>=1.11.0, but you have six 1.15.0 which is incompatible.
Successfully installed setuptools-60.1.0 wheel-0.37.1

然后我运行python3 setup.py bdist_wheel,它成功了!

running bdist_wheel
running build
running build_py
creating build
creating build/lib
creating build/lib/pypdf
copying pypdf/_version.py -> build/lib/pypdf
copying pypdf/pagerange.py -> build/lib/pypdf
copying pypdf/generic.py -> build/lib/pypdf
copying pypdf/__init__.py -> build/lib/pypdf
copying pypdf/pdf.py -> build/lib/pypdf
copying pypdf/xmp.py -> build/lib/pypdf
copying pypdf/utils.py -> build/lib/pypdf
copying pypdf/filters.py -> build/lib/pypdf
copying pypdf/merger.py -> build/lib/pypdf
/usr/local/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
running install
running install_lib
creating build/bdist.macosx-12-x86_64
creating build/bdist.macosx-12-x86_64/wheel
creating build/bdist.macosx-12-x86_64/wheel/pypdf
running install_egg_info
running egg_info
creating pypdf4.egg-info
writing manifest file 'pypdf4.egg-info/SOURCES.txt'
writing manifest file 'pypdf4.egg-info/SOURCES.txt'
Copying pypdf4.egg-info to build/bdist.macosx-12-x86_64/wheel/pypdf4-1.27.0-py3.9.egg-info
running install_scripts

【问题讨论】:

  • 尝试使用pip wheel . -w dist
  • 非常感谢@PavelHamernik。这似乎奏效了。如果您能解释为什么我在教程中给出的代码不起作用,以及为什么您的代码起作用,我会接受这个答案。再次感谢
  • 我还要问一件事,你是直接从系统中使用 python 还是使用虚拟环境。如果您确实使用了系统 python,您可以尝试在 venv docs.python.org/3/tutorial/venv.html 中构建它吗?
  • 我是在没有 venv 的情况下完成的,所以我会尝试并告诉你
  • 我刚刚尝试使用 venv,它似乎工作相同

标签: python-3.x python-wheel


【解决方案1】:

问题已在 cmets 中得到解答。解决方法是使用pip wheel . -w dist,或者创建一个虚拟环境。

我最好的猜测是你的系统包有一些问题。也许python3的多个版本。您的 pip3 命令可能指向另一个版本的 python3,这就是它可能失败的原因。

pip wheel 创建一个临时虚拟环境,在其中构建轮子。它将所有文件复制到临时目录,所以如果你有很多文件,它可能会比构建慢。

我建议始终为新项目创建虚拟环境。然后,您将拥有隔离环境,因此您可以为不同的项目提供不同的包版本。

编辑: 根据问题的更新和最新的 cmets,我认为您的 wheelsetuptools 不是最新的。即使您链接的教程也用大字体提到了这一点。

确保 pip、setuptools 和 wheel 包是最新的 https://packaging.python.org/en/latest/tutorials/installing-packages/#ensure-pip-setuptools-and-wheel-are-up-to-date

使用pip install -U pip wheel setuptools 完成,之后您提到该建筑物现在可以工作了。

如前所述pip wheel 使用最新的软件包设置虚拟环境,因此使用它没有问题。如果您查看 pip wheel 的详细输出,它会在内部使用 setup.py bdist_wheel,但会包装命令,以便在隔离环境中构建。

【讨论】:

  • 对不起,我想我错过了理解您在 cmets 中的要求。你让我尝试使用 venv。我这样做了,但是我是在运行您给我的命令而不是旧命令时这样做的,旧命令就像以前没有 venv 一样工作。我只是在 venv 中尝试了原始命令,但它没有用。我会更新我的 OP 来解释发生了什么。
  • 好的,那么您安装apt-get install python3-wheel 的还有一个问题吗?见答案stackoverflow.com/a/59596814/17726897。澄清后我会更新答案
  • 再次看到你的更新,你是不是在虚拟环境中安装了pip install wheel
  • 我将再次更新我的问题以解决这个最新的请求
  • 关于使用 apt-get,我是在 mac 上,所以我怀疑这不合适,但是如果我在这里弄错了,我很乐意尝试一下。跨度>
猜你喜欢
  • 2016-08-29
  • 2018-12-07
  • 2023-03-05
  • 1970-01-01
  • 2021-03-24
  • 2016-04-21
  • 2018-10-02
  • 2021-09-15
相关资源
最近更新 更多