Python setup.py bdist_wheel did not run successfully [Fixed]

avatar
Borislav Hadzhiev

Last updated: Apr 9, 2024
5 min

banner

# Python setup.py bdist_wheel did not run successfully

To solve the "Python setup.py bdist_wheel did not run successfully" error, run the pip install cmake command and make sure you have the wheel, setuptools and pip packages installed and upgraded.

shell
× python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [138 lines of output] running bdist_wheel

# Installing the cmake module

The first thing you should do is install cmake.

shell
pip install cmake pip3 install cmake # 👇️ If you don't have pip in your PATH environment variable python -m pip install cmake python3 -m pip install cmake

install cmake

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

# Making sure you have wheel installed

The next thing you should do is make sure you have wheel installed.

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

shell
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

install prerequisites first

Run the following command to install wheel and setuptools.

shell
pip install wheel setuptools --upgrade pip3 install wheel setuptools --upgrade python -m pip install wheel setuptools --upgrade python3 -m pip install wheel setuptools --upgrade

install wheel and setuptools

You can also upgrade your version of pip.

# 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

upgrade pip version

If you have difficulties upgrading pip, follow the instructions in this article.

# Downloading wheel from the pypi page

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".

download wheel 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

installing the wheel file

Make sure to specify the correct name of the .whl file as your version will likely be different.

You can use the Tab key to autocomplete the filename if your terminal is open in the same directory as the file.

If the error is not resolved, try upgrading your version of cmake.

shell
pip install cmake --upgrade pip3 install cmake --upgrade # 👇️ If you don't have pip in your PATH environment variable python -m pip install cmake --upgrade python3 -m pip install cmake --upgrade

upgrade cmake version

We used the --upgrade option to get the latest version of cmake.

# Reinstalling your packages

If you use a requirements.txt file, try to reinstall your packages by using the following commands.

shell
pip uninstall -r requirements.txt pip install -r requirements.txt # 👇️ Or with pip3 pip3 uninstall -r requirements.txt pip3 install -r requirements.txt

If you have multiple requirements files, follow the instructions in this article.

# Adding setup_requires to your setup.py file

If the error persists even after installing wheel 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'] )

This should resolve the issue if pip install wheel didn't get the job done.

If the error persists, 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.

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

# Create a virtual environment

If the error persists, 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 python -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 # 👇️ install cmake pip install cmake # 👇️ upgrade pip pip install --upgrade pip # 👇️ install the specific package in the virtual environment pip install requests

If the python -m venv venv command doesn't work, try one of the following commands:

  • python3 -m venv venv
  • py -m venv venv

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)

# Try running pip install in verbose mode

If none of the suggestions helped and you got the error when trying to install a package, try running the pip install command in verbose mode.

shell
pip install numpy -vvv pip3 install numpy -vvv python -m pip install numpy -vvv

run installation command in verbose mode

The -v option stands for verbose mode and can be used up to 3 times.

When the pip install command is run in verbose mode, the command shows more output and how the error occurred.

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.