Solving Python mysql error when using pip install mysqlclient : Microsoft Visual C++ 14.0 is required

Python mysql error when using pip install mysqlclient : Microsoft Visual C++ 14.0 is required is an error which occurs because of a faulty mysqlclient installation or because of missing mysqlclient related packages.

I’m going to provide a detailed and clear explanation of why this error is happening and how to solve it, I am also going to present other ways to get rid of this problem for good.

Exploring Python mysql error when using pip install mysqlclient : Microsoft Visual C++ 14.0 is required

This is an error which occurs because of a faulty mysqlclient installation or because of missing mysqlclient related packages.

Please double check so you can avoid mixing between errors. The error message should look like the error message bellow.

                                                                       #
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": 
http://landinghub.visualstudio.com/visual-cpp-build-tools
                                                                       #

Bellow, we will take care of the error using multiple possible methods according to your needs.

Solution 1 : install mysqlclient dependencies before installing mysqlclient

The first solution is to take care of some missing dependencies that usually cause this error.

You see, you do not only need to install mysqlclient. You also need to install other dependencies to make it work with no errors.

First, you should upgrade setuptools using your package manager

                                                                       #
pip install --upgrade setuptools
                                                                       #

Then you should install the mysqlclient dependencies we talked about

You can use apt like in the command bellow

                                                                       #
apt install gcc libssl-dev python3-dev build-essential default-libmysqlclient-dev
                                                                       #

Or use apt-get instead (Depending on your system)

                                                                       #
apt-get install gcc libssl-dev python3-dev build-essential default-libmysqlclient-dev
                                                                       #

Finally, you should install your version of mysqlclient of choice

                                                                       #
pip install mysqlclient==2.1.1
                                                                       #

In this example, I chose to install mysqlclient 2.1.1 which is the latest version of mysqlclient.

You should try the method bellow if this one does not work.

Solution 2 : install mysqlclient from wheel instead and avoid manually installing mysqlclient dependencies

One of the best options is to install mysqlclient from the wheel instead.

You should follow the link bellow, locate the version of Python you have and the corresponding mysqlclient version.

https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

For example, if you have Python 3.9 you should locate the following wheel files and download the version that suits your system ( Depending if your system is 64-bit or 32-bit ).

mysqlclient‑1.4.6‑cp39‑cp39‑win_amd64.whl
mysqlclient‑1.4.6‑cp39‑cp39‑win32.whl

I hope the fix above fixed your problem. Good luck.

We have reached the end of this blog post, I hope one of the methods above was helpful, thank you and good luck.

Summing-up : 

This is the end of our article, I hope the solutions I presented worked for you, Learning Python is a fun journey, do not let the errors discourage you. Keep coding and cheers.

Thank you for reading my blog post to the end, If you want to learn more about the Python programming language, check out the official Python Documentation : https://docs.python.org/3/