886

My Python package has a setup.py which builds fine locally on Ubuntu Trusty and on a fresh Vagrant Ubuntu Trusty VM when I provision it like this:

sudo apt-get install python python-dev --force-yes --assume-yes --fix-broken
curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
sudo -H pip install setuptools wheel virtualenv --upgrade

But when I do the same on a Travis CI Trusty Beta VM:

- sudo apt-get install python python-dev --force-yes --assume-yes --fix-broken
- curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python2.7
- sudo -H pip install setuptools wheel virtualenv --upgrade

I get:

python2.7 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'

This Why can I not create a wheel in python? is related but note I am installing wheel and upgrading setuptools.

Mazdak
  • 105,000
  • 18
  • 159
  • 188
nokome
  • 9,834
  • 3
  • 14
  • 15

20 Answers20

1412

Had to install the wheel package. Everything was up to date but still giving the error.

pip install wheel

then

python setup.py bdist_wheel 

worked without issues.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
frmdstryr
  • 20,142
  • 3
  • 38
  • 32
  • 44
    I needed `pip3 install wheel` - because I already had wheel installed for `pip` but not `pip3`. – TetraDev Jul 07 '19 at 06:24
  • 10
    This worked but after `pip install wheel` I had to `pip uninstall -r requirements.txt` and redo `pip install -r requirements.txt` – simple_code Aug 02 '19 at 08:21
  • 52
    `can't open file 'setup.py': [Errno 2] No such file or directory` – Cerin Aug 15 '19 at 01:50
  • 11
    @Cerin `pip install wheel` is sufficient. – Enkum Nov 14 '19 at 09:02
  • 10
    Is there a way to automatically install `wheel` in a clean virtual environment? `python3 -m venv --system-site-packages` will add too much packages. – Tobias Sette Dec 27 '19 at 02:01
  • 2
    @TobiasSette If you are using `virtualenv` and not `venv` you can specify `virtualenv myvenv --wheel ` with a valid version and it will make sure that is present in the `virtualenv` after creation. – dragon788 Jul 23 '20 at 13:47
  • perfer find the used python and execute /with/full/path/of/python -m pip install wheel – xiaojueguan Jun 14 '22 at 02:10
276

On a AWS Ubuntu 18.04 new machine, below installations are required:

sudo apt-get install gcc libpq-dev -y
sudo apt-get install python-dev  python-pip -y
sudo apt-get install python3-dev python3-pip python3-venv python3-wheel -y
pip3 install wheel

Especially the last line is a must.
However before 3 lines might be required as prerequisites.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
  • 14
    I was using `--no-install-recommends` in a Docker image ([DL3015](https://github.com/hadolint/hadolint/wiki/DL3015)) and running into this error, I needed to explicitly install `python3-wheel`. Thanks! – dimo414 Feb 08 '20 at 06:37
  • 1
    The last line should be a no-op, because wheel is already installed. Did you run it with `--upgrade`? If anyone's able to create a minimal Dockerfile starting from Ubuntu 18.04 that would be the gold standard. – l0b0 Jun 09 '20 at 20:59
  • 2
    I had to install also sudo apt install build-essential , because I had the same problem for pip3 install shap. Then it works! – Mutatos Aug 17 '20 at 10:57
  • 1
    I does make sense to `pip3 install wheel` inside virtual env. However installing it system wide with apt-get and then overriding it with pip doesn't. Or there is something more to it? – mx0 Oct 07 '20 at 14:49
  • @mx0 I wasted a lot of time came out with the above combination, seems to work for all. Please feel free to add if you find some new info. – Manohar Reddy Poreddy Oct 09 '20 at 00:20
  • But why is this necessary? I'm using Ubuntu 18.04 under WSL2, just starting a fresh env using venv. When installing numpy i get the error msg above (but it kind of works anyway?) – Einar Dec 17 '20 at 16:11
  • @Einar We all are like you faced the same issue & somehow solved it by trial and error. On why is it necessary? Those tool owners can tell, they should fix this as many people have the same issue. – Manohar Reddy Poreddy Dec 24 '20 at 04:32
  • 2
    @ManoharReddyPoreddy I don't believe this is being caused by the tool owners but the ubuntu package maintainer. `bdist_wheel` is [listed](https://github.com/pypa/wheel/blob/b8c4aa055cea0132776e7e53edce3538710d5b68/setup.cfg#L53) as an entry point by the wheel package. So installing it should put the command in your path. However the ubuntu package `python3-wheel` doesn't have contain `/usr/bin/bdist_wheel` or any entry point. Files listed here: https://packages.ubuntu.com/focal/all/python3-wheel/filelist – Philip Couling Aug 15 '21 at 20:59
119
pip install wheel

worked for me, but you can also add this

setup(
    ...
    setup_requires=['wheel']
)

to setup.py and save yourself a pip install command

Nathaniel Gentile
  • 1,753
  • 1
  • 12
  • 11
  • 3
    Those people already have wheel installed and still getting the error can add `setup_requires=['wheel']` to get rid of this error – Shankar Pandala Jun 14 '19 at 06:26
  • 3
    This does not work as expected: 1 - at first it works only because we've installed `wheel` with pip. It will fail again in a clean installation 2 - [documentation](https://setuptools.readthedocs.io/en/latest/setuptools.html) says "Note: projects listed in setup_requires will NOT be automatically installed on the system where the setup script is being run." – Tobias Sette Dec 27 '19 at 01:58
  • Not only that, @TobiasSette, but that same documentation link says: "Warning Using setup_requires is discouraged in favor of PEP-518." – Jeff Wright Jun 02 '20 at 18:24
  • 1
    @JeffWright it might be discouraged but this was the ONLY way that I could run `python setup.py bdist_wheel --universal` in a virtualenv where I had specifically uninstalled `wheel` to test. I believe the `setup_requires` triggers `easy_install` to grab `wheel` which causes it to not show up in `pip list` but you can see it in the `.eggs` folder. Since this is a local only copy of wheel it can be useful if you can't `pip install wheel` or have trouble with `pip install --user wheel`. – dragon788 Jul 23 '20 at 14:14
  • How can I install setup_requires? using `python setup.py bdist_wheel `? – alper Apr 25 '21 at 12:25
72

If you already have all the required modules installed you probably need to import the setuptools module in your setup.py file. So just add the following line at the leading of setup.py file.

import setuptools
from distutils.core import setup
# other imports and setups

This is also mentioned in wheel's documentation. https://wheel.readthedocs.io/en/stable/#usage

Mazdak
  • 105,000
  • 18
  • 159
  • 188
  • 12
    This worked for me. I was using distutils instead of setuptools for the setup and I already had the wheel package installed. – Alex Kaszynski Oct 29 '18 at 11:15
56

This problem is due to:

  • an old version of pip (6.1.1) being installed for Python 2.7
  • multiple copies of Python 2.7 installed on the Trusty Beta image
  • a different location for Python 2.7 being used for sudo

It's all a bit complicated and better explained here https://github.com/travis-ci/travis-ci/issues/4989.

My solution was to install with user travis instead of sudo:

- pip2.7 install --upgrade --user travis pip setuptools wheel virtualenv
nokome
  • 9,834
  • 3
  • 14
  • 15
46

in my case, the version of wheel/pip/setuptools created by venv is too old. this works:

venv/bin/pip  install --upgrade pip wheel setuptools
wynemo
  • 2,293
  • 2
  • 19
  • 10
37

This error is weird as many proposed answers and got mixed solutions. I tried them, add them. It was only when I added pip install --upgrade pip finally removed the error for me. But I have no time to isolate which is which,so this is just fyi.

daparic
  • 3,794
  • 2
  • 36
  • 38
23

In your setup.py, if you have:

from distutils.core import setup

Then, change it to

from setuptools import setup

Then re-create your virtualenv and re-run the command, and it should work.

Philippe Remy
  • 2,967
  • 4
  • 25
  • 39
19

I already had wheel installed so I tried to uninstall and reinstall, and it fixed the issue:

pip uninstall wheel
pip install wheel

Weird...

Jerther
  • 5,558
  • 8
  • 40
  • 59
  • FWIW I just encountered this error and uninstalling and re-installing worked for me – Vincent May 02 '19 at 02:04
  • I ran `pip install wheel` from an activated virtualenv which fixed it, but the fix persisted after removing and recreating the virtualenv, which makes no sense. I would have expected any effects of `pip install wheel` to go away with the virtualenv. – aggieNick02 May 12 '21 at 18:17
14

My fix was apt install python3-dev

7029279
  • 485
  • 1
  • 6
  • 15
10

Perhaps, your pip version is outdated. I experienced the same problem in WSL while installing modules in a newly created virtual environment. I was able to resolve it by running the following command:

$ ./bin/python3 -m pip install --upgrade pip 
Sathiya Sarathi
  • 429
  • 6
  • 23
9

I did apt-get install python3-dev in my Ubuntu and added setup_requires=["wheel"] in setup.py

Rohit.007
  • 3,414
  • 2
  • 21
  • 33
6

Try modifying the setup.py file by importing setup from setuptools instead of distutils.core

  • Worked for me! I was migrating a package from Python2 to Python3 and unfortunately couldn't find a guide for that. Anyone doing the same and getting frustrated with this problem, this might do it for you! – skytreader Apr 24 '19 at 20:14
6

If you're using setup.cfg files, add this before the install_require part:

setup_requires =
    wheel

Example of setup.cfg project :

# setup.py
from setuptools import setup

setup()
# setup.cfg
[metadata]
name = name
version = 0.0.1
description = desc
long_description = file: README.md
long_description_content_type = text/markdown
url = url
author = author
classifiers =
    Programming Language :: Python
    Programming Language :: Python :: 3

[options]
include_package_data = true
packages = find:
setup_requires =
    wheel
install_requires =
    packages
    packages
    packages
sodimel
  • 864
  • 2
  • 11
  • 24
3

It helped me to follow instructions in here:

https://packaging.python.org/guides/installing-using-linux-tools/

Debian/Ubuntu

Python 2:

sudo apt install python-pip

Python 3:

sudo apt install python3-venv python3-pip
1

Using Ubuntu 18.04 this problem can be resolved by installing the python3-wheelpackage.

Usually this is installed as a dependency on any Python package. But especially when building container images you often work with --no-install-recommends and therefore it is often missing and has to be installed manually first.

Christian Berendt
  • 1,617
  • 13
  • 17
1

If none of the above works for you, perhaps you are experiencing the same problem that I did. I was only seeing this error when attempting to install pyspark. The solution is explained in this other stackoverflow question unable to install pyspark.

I post this b/c it wasn't immediately obvious to me from the error message that my issue was stemming solely from pyspark's dependency on pypandoc and I'm hoping to save others from hours of head scratching! =)

Ben
  • 1,620
  • 18
  • 11
1

I tried the pip install wheel instruction given above, but it didn't work because I was told that the requirement was already satisfied. It turned out that I was using python-3.10 and pip from my python-3.9 site packages. I finally realized that by entering python --version and pip --version and comparing the directories.

With this realization, I installed a new version of pip to go with my python-3.10, installed the wheel, and everything worked.

Shunya
  • 2,344
  • 4
  • 16
  • 28
0

Not related to Travis CI but I ran into similar problem trying to install jupyter on my Mac OSX 10.8.5, and none of the other answers was of help. The problem was caused by building the "wheel" for the package called pyzmq, with error messages filling hundreds of pages.

The solution I found was to directly install an older version of that package:

python -m pip install pyzmq==17 --user

After that, the installation of jupyter succeded without errors.

Adrian W
  • 4,563
  • 11
  • 38
  • 52
Dmitri Zaitsev
  • 13,548
  • 11
  • 76
  • 110
0

as @Philippe Remy mention, should import from setuptools

from setuptools import setup

reference: Official doc https://setuptools.pypa.io/en/latest/index.html

chilin
  • 420
  • 7
  • 9