How To Solve The Error “Failed building wheel for mysqlclient” in Python

The Error “Failed building wheel for mysqlclient” in Python happens when you try to install the mysqlclient package, and sometimes, it is not in wheel format. So, pip will install this package unsuccessfully. To fix this Error, you can not use the usual command to install the mysqlclient package. Let’s learn more about it with the explanation and examples below.

What Is The Cause Of This Error?

The Error “Failed building wheel for mysqlclient” in Python happens when you try to install the mysqlclient package, but sometimes, this package is not in wheel format, and pip can not install this package as usual. 

Look at the example below to learn more about this Error when running this statement in the command prompt.

pip install mysqlclient

Output

Failed building wheel for mysqlclient

How To Fix The Error “Failed building wheel for mysqlclient” in Python

To solve the Error “Failed building wheel for mysqlclient” in Python, you can follow these solutions below to learn how to install the mysqlclient in Python in different environments.

Install the dependencies first

A simple way to fix the Error: Failed building wheel for mysqlclient is to install the dependencies first. After that, you can install the mysqlclient package as usual.

Running the following command below to install the dependencies.

sudo apt-get install python3.7-dev default-libmysqlclient-dev

After that, you can install the mysqlclient package as usual.

pip install mysqlclient

For Ubuntu

On the Ubuntu environment, you can install the following library first by running the following command.

sudo apt-get install libssl-dev

After that, you can install the mysqlclient package as usual.

pip install mysqlclient

For MacOS

You can fix the Error “Failed building wheel for mysqlclient” in Python on the macOS by running the following command.

$ brew install mysql
$ pip install mysqlclient

Install the specified version

A simple solution but almost effective is installing the mysqlclient with the specified version. After doing that, the Error will be fixed.

Running the following command below.

pip install mysqlclient==1.3.12

Besides, you can learn more about how to fix the most common errors that often appear in Python here.

Summary

We have shown you why the Error “Failed building wheel for mysqlclient” in Python and how to fix it in the specified environment. Choose the solution that is suitable for your environment. If you have any questions about this article, leave your comment below, and I will answer your questions. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *