Error: invalid command 'bdist_wheel' in Python [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 9, 2024
4 min

banner

# Error: invalid command 'bdist_wheel' in Python

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.

shell
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>

# Install the prerequisites on Debian (Ubuntu)

First, If you are on Debian (Ubuntu), install the prerequisites.

shell
# ๐Ÿ‘‡๏ธ 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

install prerequisites debian ubuntu

These are meta-packages and header files that are necessary for compiling software.

# Install the wheel package

Run one of the following commands to install wheel.

shell
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

# Upgrading your version of pip

You should also upgrade your version of pip.

Here are the commands for upgrading pip on all operating systems.

Which command works depends on your operating system and your version of Python.
shell
# ๐Ÿ‘‡๏ธ 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.

shell
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

# Download the 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".

Once you download the file, open your terminal in the folder where the .whl file is located and install it.
shell
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

pip install wheel

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.

shell
pip install cmake pip3 install cmake python -m pip install cmake python3 -m pip install cmake py -m pip install cmake

install cmake

The cmake package is used to control the software compilation process.

# Importing setuptools in your setup.py file

If the error persists and you have a setup.py file in the root directory of your project, add the following line to it.

setup.py
setup( # rest, setup_requires=['wheel'] )

If the error is not resolved, try adding the following lines at the top of your setup.py file

setup.py
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.

# Create a virtual environment

If that didn't help, try creating a virtual environment.

  1. Create a virtual environment.
  2. Activate the virtual environment.
  3. Run the pip install command with the virtual environment active.
shell
# ๐Ÿ‘‡๏ธ 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.

# Install the latest version of Python

You can check your Python version with the python --version command.

shell
python --version python3 --version

get python version

You can download the latest version from the official python.org website.

Make sure to tick the following options if you get prompted:

  • Install launcher for all users (recommended)
  • Add Python to PATH (this adds Python to your PATH environment variable)
I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev