Mathew
Mathew

Reputation: 1430

unable to make a python3 wheel because bdist_wheel is an invalid command

NOTE: the solution was to update my version of wheels using this command:

pip install -U pip wheel setuptools

The original question

I am trying to make a wheel in python3, so I followed this tutorial:
https://medium.com/swlh/beginners-guide-to-create-python-wheel-7d45f8350a94

However, when I ran the command python3 setup.py bdist_wheel I got this error:

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'

I then checked out this answer on stack overflow:
How to fix `error: invalid command 'bdist_wheel'`?

and tried re-installing wheel like so: pip3 install wheel, however I got this message:

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)

I tried running python3 setup.py bdist_wheel again, however it still gave the same error, so I then checked the page: https://github.com/Homebrew/homebrew-core/issues/76621 that the above message recommended to me, however it told me there is nothing for me to do at this time:

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.

At this point, I am unsure where to go next to resolve my problem. To be clear, my goal is to make a python3 wheel. At the moment, I want in particular to make a wheel for PyPDF4: https://github.com/claird/PyPDF4, however I would more generally like to be able to make wheels for any package, and the problem I am having doesn't seem to have anything to do with this particular package, so this additional information should be unnecessary.

In case this is relevant, I am on macos monterey 12.0.1

Regarding venv:
I created a virtualenv with this command: virtualenv . and then activated it with source bin/activate. I then ran python3 setup.py bdist_wheel to see if I could use the original command suggested to me in the tutorial, however again, I got the same error as is given at the top of this post. So it seems to me that making a venv doesn't fix the problem.

Installing wheel into the venv

Here is the result of my attempt to install wheel into the virtual environment prior to building the wheel. As can be seen below, it also doesn't work

➜  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) ✗

Small note

@Pavel Hamerník, Thanks for all the help so far. If you're tired of dealing with this question, just say so and I'll accept your answer as is. I have successfully accomplished my goal of making a wheel, so at this point I am simply pursuing this in an attempt to make a more complete post here on stackoverflow. If you feel similarly to me that this is worth while, then we should continue working to find out what exactly the problem is. Thanks again

Updating to the newest version

I ran pip3 install -U pip wheel setuptools and got this message:

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

I then ran python3 setup.py bdist_wheel and it worked!

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

Upvotes: 2

Views: 14459

Answers (1)

Pavel Hamern&#237;k
Pavel Hamern&#237;k

Reputation: 141

The question was answered in the comments. The solution was to use pip wheel . -w dist, or to create a virtual environment.

My best guess is you have some problems with your system packages. Maybe multiple versions of python3. Your pip3 command could point to another version of python3 that's why it probably failed.

pip wheel creates a temporary virtual environment where it builds the wheel. It copies all files to the temp directory, so if you have a lot of files it can be slower then the build.

I would suggest always creating a virtual environment for new projects. You'll have then isolated environment so you can have different package versions for different projects.

Edit: According to the update of the question and latest comments I think your wheel or setuptools wasn't up-to-date. Even the tutorial you linked has this mentioned with a large font.

Ensure pip, setuptools and wheel packages are up to date https://packaging.python.org/en/latest/tutorials/installing-packages/#ensure-pip-setuptools-and-wheel-are-up-to-date

Which was done with pip install -U pip wheel setuptools and after that you mentioned that the building now works.

As said before pip wheel setups the virtual environment with the latest packages, so there wasn't a problem using it. If you look on verbose output of pip wheel it uses setup.py bdist_wheel internally but wraps the command so it builds in an isolated environment.

Upvotes: 1

Related Questions