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

PythonTravis Cisetup.pyPypi

Python Problem Overview


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 https://stackoverflow.com/questions/26664102/why-can-i-not-create-a-wheel-in-python is related but note I am installing wheel and upgrading setuptools.

Python Solutions


Solution 1 - Python

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.

Solution 2 - Python

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.

Solution 3 - Python

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

Solution 4 - Python

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

Solution 5 - Python

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

Solution 6 - Python

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

Solution 7 - Python

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.

Solution 8 - Python

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.

Solution 9 - Python

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

pip uninstall wheel
pip install wheel

Weird...

Solution 10 - Python

My fix was apt install python3-dev

Solution 11 - Python

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 

Solution 12 - Python

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

Solution 13 - Python

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

Solution 14 - Python

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

Solution 15 - Python

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

Solution 16 - Python

Method 1: update pip

python3 -m pip install --upgrade pip

Method 2: Had to install the wheel package

pip install wheel
python setup.py bdist_wheel 

Get some more solution, exerror, github

Solution 17 - Python

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.

Solution 18 - Python

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! =)

Solution 19 - Python

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.

Solution 20 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnokomeView Question on Stackoverflow
Solution 1 - PythonfrmdstryrView Answer on Stackoverflow
Solution 2 - PythonManohar Reddy PoreddyView Answer on Stackoverflow
Solution 3 - PythonNathaniel GentileView Answer on Stackoverflow
Solution 4 - PythonMazdakView Answer on Stackoverflow
Solution 5 - PythonnokomeView Answer on Stackoverflow
Solution 6 - PythonwynemoView Answer on Stackoverflow
Solution 7 - PythoneigenfieldView Answer on Stackoverflow
Solution 8 - PythonPhilippe RemyView Answer on Stackoverflow
Solution 9 - PythonJertherView Answer on Stackoverflow
Solution 10 - Python7029279View Answer on Stackoverflow
Solution 11 - PythonSathyasarathi GunasekaranView Answer on Stackoverflow
Solution 12 - PythonRohit.007View Answer on Stackoverflow
Solution 13 - PythonShubham LaddhaView Answer on Stackoverflow
Solution 14 - PythonsodimelView Answer on Stackoverflow
Solution 15 - PythonSergey SolovyevView Answer on Stackoverflow
Solution 16 - PythonMD SHAYONView Answer on Stackoverflow
Solution 17 - PythonChristian BerendtView Answer on Stackoverflow
Solution 18 - PythonBenView Answer on Stackoverflow
Solution 19 - PythonDmitri ZaitsevView Answer on Stackoverflow
Solution 20 - Pythonuser2419194View Answer on Stackoverflow