【发布时间】: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,它似乎工作相同