[Fix] Invalid Command: “bdist_wheel” Error Easily

Many times while running the setup.py file, we tend to see the error stating invalid command: “bdist_wheel”, and get worried about what it is all about and how to solve this error. We will be seeing what causes this issue and how to fix this error easily.

What is the setup.py file?

We use the setup.py file to build and distribute python packages. We can build our own python package and distribute it all over the internet.

The setup.py file contains information about the package, like its name, dependencies, and instructions on how to install the package, which will be used by pip to install the package.

When do we get the “bdist_wheel” error?

We can build our own package in Python and then distribute it; we need to have a certain directory structure.

A minimalistic folder structure for the project to be distributed.
The folder structure for our project

setup.py normally contains this information:-

from setuptools import setup

setup(
	name='package_to_be_distributed',
	version='0.1',
	description='Python package describing what needs to be done',
	author='name_of_the_author',
	author_email='email of the author',
	packages=['package_to_be_distributed'],
	install_requires=[
		List of other packages upon which our package is dependent
	],
)

To use setup.py, we need to install setuptools, which we can install using:-

pip install setuptools

To use setup.py further, we need to install setuptools, after which we can use it by writing the command:

python setup.py sdist bdist_wheel

This step creates a distribution of our package in the dist directory if run correctly.

But many times, we may get an error saying invalid command: “bdist_wheel”.

What is bdist_wheel?

bdist_wheel creates a binary distribution, which is the precompiled version of our package’s modules; sometimes, we get to see invalid command:

bdist_wheel

To solve this issue, we need to install the wheel package and its prerequisites in the environment.

There are various ways of solving the above issue.

How to fix Invalid Command: “bdist_wheel” Error

Reinstalling wheel

If you are on ubuntu, then you would need to install the following before the installation of the wheel –

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

After that, we can install the wheel, simply using pip as –

pip install wheel

That should solve the issue; if not, then we can move on to other steps.

Upgrading pip

We can upgrade the pip before installing anything else:-

We can use the following command if pip is already installed in our system.

pip install --upgrade pip

If we have not set pip as an environment variable, then we can use the following command to upgrade pip –

python -m pip install --upgrade pip

If it shows a permission error, then we can use the following command –

pip install --upgrade pip --user

We can also use the below command if we are using Ubuntu/Debian:

sudo apt-get update && apt-get upgrade python-pip

After the upgradation of pip, we can upgrade setuptools:-

pip install --upgrade setuptools

Or, if pip is not in Python, then we can use:-

python -m pip install --upgrade setuptools

Download the wheel from its page

If even after this, the error is not resolved, then we should download the “wheel” from the PyPI page of the wheel. We can download it by clicking on the .whl file under “Built distribution”.

We should move into the directory where the wheel is installed and then run the following commands,

pip install wheel-0.37.1-py2.py3-none-any.whl

Or, if pip is not in the PATH, then we should use the following command:-

python -m pip install wheel-0.37.1-py2.py3-none-any.whl

If an error is not resolved, we can install the CMake package. The “CMake” package is used to control the software compilation process.

pip install cmake

Or,

python -m pip install cmake

Creating the Virtual Environment

We can create and activate the virtual environment and then upgrade pip and install the package which we are trying to install.

To create a virtual environment, use the below command:

python3 -m venv venv

After that, activate the virtual environment, if on Unix or macOS:

source venv/bin/activate

On Windows, we should use the following command:-

venv\Scripts\activate.bat

After that, we should upgrade the pip and then install the package, whichever we want to install:-

pip install --upgrade pip
pip install requests

Reinstalling Python

If even after this, we can’t get rid of the error, then we can reinstall Python from its official website and make sure to add Python to the path and install the launcher for all users.

Manipulating setup.py

Sometimes, the wheel doesn’t work even after the installation, that we can try adding a line in our setup.py file as an argument to the setup function, where ‘…’ represents all the previous arguments to the setup function –

setup( ... ,setup_requires=['wheel'] )

Fixing the “bdist_wheel” error while installing numpy

If you face some error while installing of NumPy package, then simply just follow the above-written steps, it will help you to get rid of the problem.

What to do if we are getting a “bdist_wheel” error inside docker?

Sometimes we may get to see the error inside dockerfile.

What we can do is we should enter the below lines inside dockerfile before anything else.

RUN pip install wheel

What to do if we are getting the “bdist_wheel” error while installing ansible using pip?

We just simply need to follow the above-mentioned steps in order to solve these types of problems.

FAQs

Why do we need setup.py?

setup.py is used to tell the package manager ‘pip’ about the package, what are its functions, its authors, the packages on which it depends, etc.

Can reinstalling or updating Linux be a fix for the error invalid command: “bdist_wheel”?

Yes, it can be a fix for the problems related to packages.

Can we build and distribute our own packages in Python?

Yes, we can build and make our package available, which can be downloaded using pip into other computers.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments