Why is python setup.py saying invalid command 'bdist_wheel' on Travis CI?
Asked Answered
E

22

913

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.

Etheline answered 15/1, 2016 at 20:19 Comment(0)
S
1467

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.

Spanking answered 1/7, 2017 at 15:3 Comment(7)
I needed pip3 install wheel - because I already had wheel installed for pip but not pip3.Oma
This worked but after pip install wheel I had to pip uninstall -r requirements.txt and redo pip install -r requirements.txtCognac
can't open file 'setup.py': [Errno 2] No such file or directoryMorehead
@Morehead pip install wheel is sufficient.Apolitical
Is there a way to automatically install wheel in a clean virtual environment? python3 -m venv --system-site-packages will add too much packages.Kinata
@TobiasSette If you are using virtualenv and not venv you can specify virtualenv myvenv --wheel <VERSION> with a valid version and it will make sure that is present in the virtualenv after creation.Timi
perfer find the used python and execute /with/full/path/of/python -m pip install wheelGabel
G
280

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.

Gamine answered 5/1, 2020 at 3:38 Comment(8)
I was using --no-install-recommends in a Docker image (DL3015) and running into this error, I needed to explicitly install python3-wheel. Thanks!Sweetsop
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.Gantry
I had to install also sudo apt install build-essential , because I had the same problem for pip3 install shap. Then it works!Rosannarosanne
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?Nona
@Nona 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.Gamine
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?)Anetteaneurin
@Anetteaneurin 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.Gamine
@ManoharReddyPoreddy I don't believe this is being caused by the tool owners but the ubuntu package maintainer. bdist_wheel is listed 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: packages.ubuntu.com/focal/all/python3-wheel/filelistDudeen
O
120
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

Octaviaoctavian answered 22/2, 2019 at 19:13 Comment(5)
Those people already have wheel installed and still getting the error can add setup_requires=['wheel'] to get rid of this errorSagittate
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 says "Note: projects listed in setup_requires will NOT be automatically installed on the system where the setup script is being run."Kinata
Not only that, @TobiasSette, but that same documentation link says: "Warning Using setup_requires is discouraged in favor of PEP-518."Rabin
@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.Timi
How can I install setup_requires? using python setup.py bdist_wheel ?Maritzamariupol
L
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

Laryssa answered 13/5, 2018 at 8:11 Comment(1)
This worked for me. I was using distutils instead of setuptools for the setup and I already had the wheel package installed.Atrium
E
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
Etheline answered 18/1, 2016 at 3:18 Comment(3)
In my case, sudo -H pip install setuptools --upgrade solved the problem.Precede
@MartinThoma Thanks for your tip. It worked for me after issuing sudo -H pip install wheel --upgradePredicable
Upgrading pip was enough in my case, from 9.0.1 to 20.0.2Scratchboard
H
47

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
Haily answered 27/12, 2019 at 19:15 Comment(0)
R
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.

Retaliate answered 22/3, 2018 at 10:55 Comment(0)
T
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.

Theatricals answered 3/3, 2020 at 10:52 Comment(3)
This fixes my problem. Thank you. +1Lefton
This should be the answer. Thank youFromma
This shoud be answer +1Ranzini
A
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...

Aiaia answered 4/9, 2018 at 18:57 Comment(2)
FWIW I just encountered this error and uninstalling and re-installing worked for meAuthoritarian
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.Shauna
H
15

My fix was apt install python3-dev

Hoopes answered 19/2, 2019 at 23:48 Comment(1)
Yes, and add setup_requires=["wheel"] to your setup.pyRamonaramonda
A
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 
Antenatal answered 12/5, 2021 at 7:31 Comment(0)
B
9

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

Bellerophon answered 3/3, 2020 at 11:6 Comment(2)
It may be enough to run pip install wheel.Misdeem
Where is setup.py supposed to be located? In other words: which setup.py?Innate
M
6

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

Murmuration answered 16/3, 2019 at 11:8 Comment(1)
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!Orton
A
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
Anonymous answered 23/5, 2020 at 11:32 Comment(0)
G
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
Genic answered 15/10, 2019 at 14:47 Comment(1)
This works for me. first sudo apt install python3-venv python3-pip then pip3 install wheelMotte
C
2

As @frmdstryr said, you can just use the following command.

pip install wheel
Categorical answered 1/2 at 9:20 Comment(0)
A
1

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.

Acceptance answered 14/7, 2019 at 4:20 Comment(0)
A
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.

Alkaloid answered 22/10, 2019 at 12:39 Comment(0)
R
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! =)

Redmund answered 5/10, 2020 at 18:14 Comment(0)
C
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.

Concelebrate answered 12/1, 2022 at 17:38 Comment(0)
R
0

as @Philippe Remy mention, should import from setuptools

from setuptools import setup

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

Ranzini answered 24/8, 2022 at 1:14 Comment(0)
K
0

For the project's own environment and custom setup.py file will be this way

Activate environment

python -m venv venv or python3 -m venv venv

Mac/Linux
. /venv/env/activate

Windows

.\venv\Scripts\activate

setup.py file

 install_requires=["wheel >= x.x.x",],
 extras_require={
      "dev": [" "],
 },

pip install .

Or use

pip install wheel

and finally use your command

python setup.py bdist_wheel
or
python3 setup.py bdist_wheel
Katar answered 5/1 at 17:49 Comment(1)
python setup.py bdist_wheel is deprecated: packaging.python.org/en/latest/discussions/setup-py-deprecatedThick

© 2022 - 2024 — McMap. All rights reserved.