195

Here are the commands I am running:

$ python 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'

$ pip --version
pip 1.5.6 from /usr/local/lib/python3.4/site-packages (python 3.4)

$ python -c "import setuptools; print(setuptools.__version__)"
2.1

$ python --version
Python 3.4.1

$ which python
/usr/local/bin/python

Also, I am running a mac with homebrewed python

Here is my setup.py script: https://gist.github.com/cloudformdesign/4791c46fe7cd52eb61cd

I'm going absolutely crazy -- I can't figure out why this wouldn't be working.

cbron
  • 4,036
  • 3
  • 33
  • 40
vitiral
  • 8,446
  • 8
  • 29
  • 43

8 Answers8

310

Install the wheel package first:

pip install wheel

The documentation isn't overly clear on this, but "the wheel project provides a bdist_wheel command for setuptools" actually means "the wheel package...".

Thomas Orozco
  • 53,284
  • 11
  • 113
  • 116
  • 1
    So that spit out the file: nioblocks-1.01-cp34-cp34m-macosx_10_9_x86_64.whl -- will this work with any OS, or is there something else I have to do to get it to work? (the "package" is just a bunch of dependencies for pip to install right now) – vitiral Oct 30 '14 at 22:16
  • 1
    @GarrettLinux I wouldn't know, I'm sorry, but I'd encourage you to ask a separate question for that ; ) – Thomas Orozco Oct 30 '14 at 22:19
  • 1
    I fixed that problem too -- adding any file to the setup.py file gave it a general wheel. Check out the updated code in my question for example. – vitiral Nov 05 '14 at 14:11
  • You can get the OP's error even with wheel installed, if the setup.py somehow uses distutils instead of setuptools (as was case for me), see the answer by geographika. – Oliver Dec 28 '16 at 17:54
  • 4
    For me the problem was old version of pip. fixed by `pip install --upgrade pip` – Ryu_hayabusa Jun 14 '17 at 10:21
  • One may also need `sudo pip install wheel` if encountering permission problems. – CodeBrew Jul 12 '17 at 23:26
  • @CodePlumber my favorite is `pip install wheel --user` for installing "globally". – vitiral Apr 12 '18 at 05:43
  • I was having the same issue, and `pip install wheel` didn't do anything, but `conda install wheel` solved it. – La Cordillera Mar 12 '21 at 05:10
170

I also ran into the error message invalid command 'bdist_wheel'

It turns out the package setup.py used distutils rather than setuptools. Changing it as follows enabled me to build the wheel.

#from distutils.core import setup
from setuptools import setup
geographika
  • 6,458
  • 4
  • 38
  • 56
  • 1
    yup, I had that problem at one time as well! Very important, and the error message is poor. – vitiral Jan 09 '15 at 19:50
  • @geographika yes this is command also the documentation on https://docs.python.org/2/distutils/setupscript.html would replicate the issues you are seeig as it uses disutils – JamesD Jun 22 '15 at 13:18
  • 4
    May also be necessary to change `from distutils.core import Extension, Command` to `from setuptools import Extension, Command` at least for package I was working with. – eseglem Oct 13 '16 at 23:14
  • I got this error for pycrypto and it wasn't even importing setup. However, I added `from setuptools import setup` at the beginning and it fixed the issue. – haridsv Mar 21 '17 at 11:08
39

Update your setuptools, too.

pip install setuptools --upgrade

If that fails too, you could try with additional --force flag.

luckydonald
  • 5,976
  • 4
  • 38
  • 58
  • 1
    my setuptools was removed, or something was wrong. So I had to do : pip install setuptools --upgrade --force – nycynik Apr 11 '16 at 23:23
14

I also ran into this all of a sudden, after it had previously worked, and it was because I was inside a virtualenv, and wheel wasn’t installed in the virtualenv.

jbg
  • 4,903
  • 1
  • 27
  • 30
11

Update your pip first:

pip install --upgrade pip

for Python 3:

pip3 install --upgrade pip
Tombart
  • 30,520
  • 16
  • 123
  • 136
  • 1
    This is the most useful answer now. Newer versions of pip install don't use bdist_wheel, so just upgrading pip worked for me, without needing to install/update setuptools or wheel – theferrit32 Oct 25 '18 at 03:15
5

Throwing in another answer: Try checking your PYTHONPATH.

First, try to install wheel again:

pip install wheel

This should tell you where wheel is installed, eg:

Requirement already satisfied: wheel in /usr/local/lib/python3.5/dist-packages

Then add the location of wheel to your PYTHONPATH:

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.5/dist-packages/wheel

Now building a wheel should work fine.

python setup.py bdist_wheel
theo-brown
  • 653
  • 10
  • 27
4

It could also be that you have a python3 system only. You therefore have installed the necessary packages via pip3 install , like pip3 install wheel.

You'll need to build your stuff using python3 specifically.

python3 setup.py sdist
python3 setup.py bdist_wheel

Cheers.

2

I tried everything said here without any luck, but found a workaround. After running this command (and failing) : bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

Go to the temporary directory the tool made (given in the output of the last command), then execute python setup.py bdist_wheel. The .whl file is in the dist folder.

Aigrefin
  • 125
  • 8