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.

2
  • 2
    And you have installed the wheel package as Thomas' answer advises?
    – Martijn Pieters
    Oct 30, 2014 at 22:10
  • 1
    I have the same problem. But it seems that i didn't use sudo before the commend. After use the commend with administrate permission. it worked.
    – hunter
    Jan 21, 2016 at 2:49

8 Answers 8

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...".

8
  • 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, 2014 at 22:16
  • 1
    @GarrettLinux I wouldn't know, I'm sorry, but I'd encourage you to ask a separate question for that ; ) Oct 30, 2014 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 5, 2014 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, 2016 at 17:54
  • 4
    For me the problem was old version of pip. fixed by pip install --upgrade pip Jun 14, 2017 at 10:21
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
4
  • 1
    yup, I had that problem at one time as well! Very important, and the error message is poor.
    – vitiral
    Jan 9, 2015 at 19:50
  • @geographika yes this is command also the documentation on docs.python.org/2/distutils/setupscript.html would replicate the issues you are seeig as it uses disutils
    – JamesD
    Jun 22, 2015 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, 2016 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, 2017 at 11:08
39

Update your setuptools, too.

pip install setuptools --upgrade

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

1
  • 1
    my setuptools was removed, or something was wrong. So I had to do : pip install setuptools --upgrade --force
    – nycynik
    Apr 11, 2016 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.

0
11

Update your pip first:

pip install --upgrade pip

for Python 3:

pip3 install --upgrade pip
1
  • 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 Oct 25, 2018 at 3: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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.