Last updated: Apr 9, 2024
Reading timeยท4 min
The Python "error: invalid command 'bdist_wheel'" occurs when the wheel
package is not installed in the environment.
To solve the error, install the prerequisites and run the pip install wheel
command.
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' Collecting <package> Using cached <package>-X.Y.Z.tar.gz (567 kB) Preparing metadata (setup.py): started Preparing metadata (setup.py): finished with status 'done' Using legacy 'setup.py install' for <package>, since package 'wheel' is not installed. Installing collected packages: <package>
First, If you are on Debian (Ubuntu), install the prerequisites.
# ๐๏ธ Only needed if on Debian (Ubuntu) sudo apt-get install gcc libpq-dev build-essential -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
These are meta-packages and header files that are necessary for compiling software.
wheel
packageRun one of the following commands to install wheel.
pip install wheel pip3 install wheel # ๐๏ธ If you don't have pip in PATH python -m pip install wheel python3 -m pip install wheel # ๐๏ธ On Windows py -m pip install wheel
pip
You should also upgrade your version of pip.
Here are the commands for upgrading pip
on all operating systems.
# ๐๏ธ If you have pip already installed pip install --upgrade pip # ๐๏ธ If your pip is aliased as pip3 (Python 3) pip3 install --upgrade pip # ๐๏ธ If you don't have pip in your PATH environment variable python -m pip install --upgrade pip # ๐๏ธ If you don't have pip in your PATH environment variable python3 -m pip install --upgrade pip # ๐๏ธ If you have easy_install easy_install --upgrade pip # ๐๏ธ If you get a permissions error sudo easy_install --upgrade pip # ๐๏ธ If you get a permissions error when upgrading `pip` pip install --upgrade pip --user # ๐๏ธ Upgrade pip scoped to the current user (if you get a permissions error) python -m pip install --user --upgrade pip python3 -m pip install --user --upgrade pip # ๐๏ธ Installing directly from get-pip.py (MacOS and Linux) curl https://bootstrap.pypa.io/get-pip.py | python # ๐๏ธ If you get permissions issues curl https://bootstrap.pypa.io/get-pip.py | sudo python # ๐๏ธ Alternative for Ubuntu/Debian sudo apt-get update && apt-get upgrade python-pip # ๐๏ธ Alternative for Red Hat / CentOS / Fedora sudo yum install epel-release sudo yum install python-pip sudo yum update python-pip
After you upgrade pip
,
upgrade setuptools by running one of
the following commands.
pip install --upgrade setuptools pip3 install --upgrade setuptools # ๐๏ธ If you don't have pip in PATH python -m pip install --upgrade setuptools python3 -m pip install --upgrade setuptools py -m pip install --upgrade setuptools
wheel
package from the pypi
page of wheel
If the error is not resolved, download the wheel
package from the
pypi page of wheel by clicking on the
.whl
file under "Built Distribution".
.whl
file is located and install it.pip install wheel-0.37.1-py2.py3-none-any.whl pip3 install wheel-0.37.1-py2.py3-none-any.whl python -m pip install wheel-0.37.1-py2.py3-none-any.whl python3 -m pip install wheel-0.37.1-py2.py3-none-any.whl
Make sure to specify the correct name of the .whl
file as your version will
likely be different.
If the error is not resolved, try installing the cmake
package.
pip install cmake pip3 install cmake python -m pip install cmake python3 -m pip install cmake py -m pip install cmake
The cmake package is used to control the software compilation process.
setuptools
in your setup.py
fileIf the error persists and you have a setup.py
file in the root directory of
your project, add the following line to it.
setup( # rest, setup_requires=['wheel'] )
If the error is not resolved, try adding the following lines at the top of your
setup.py
file
import setuptools from setuptools import setup # rest of your imports below
The setup.py
file should be in the root directory of your Python project and
is used to store metadata about the program.
If that didn't help, try creating a virtual environment.
pip install
command with the virtual environment active.# ๐๏ธ Use the correct version of Python when creating VENV python3 -m venv venv # ๐๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # ๐๏ธ Upgrade pip pip install --upgrade pip # ๐๏ธ Install the specific package in the virtual environment pip install requests
Make sure to use the correct command to activate your virtual environment depending on your operating system and your shell.
Your virtual environment will use the version of Python that was used to create it.
If that didn't help, try installing the latest version of Python.
You can check your Python version with the python --version
command.
python --version python3 --version
You can download the latest version from the official python.org website.
Make sure to tick the following options if you get prompted: