pip install mysqlclient returns "fatal error C1083: Cannot open file: 'mysql.h': No such file or directory

You can download unofficial windows binaries for your python version using https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient. Then install it using pip. This way you'll be able to avoid the hassle of dealing with visual studio build tools.

Just download the mysqlclient.whl file most applicable to you. I think in your case it'll be

mysqlclient‑1.3.13‑cp36‑cp36m‑win_amd64.whl

and run

pip install "path to the downloaded .whl file"

This error occurs when trying to install mysqlclient for python32 in 64 bit environments. Uninstall python and re-install 64 bit version. Then pip install mysqlclient will run with no errors.


Well probably,this is one of the stupidest errors i have ever witnessed.
I have Python 3.7.3 32bit along with latest pip3 and i was installing wheels to my Python....and i stumbled on this STUPID error....
Probably my situation is a bit different but you can resolve it just by looking carefully at the error.... at first it seems something is missing and you start blaming you, Windows ,32/64bit and the list goes on and on..
Take a step back...just take a step back and just read the nasty red error message.... read it really well.
In my case it was

ERROR: Command errored out with exit status 1:
     command: 'c:\users\myUserName\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-install-z7x81g2q\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-install-z7x81g2q\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\MASTER~1\AppData\Local\Temp\pip-record-z1mvci5v\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\MASTER~1\AppData\Local\Temp\pip-install-z7x81g2q\mysqlclient\
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    creating build\lib.win32-3.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb
    creating build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win32-3.7
    creating build\temp.win32-3.7\Release
    creating build\temp.win32-3.7\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -Ic:\users\MyUserName\appdata\local\programs\python\python37-32\include -Ic:\users\MyUserName\appdata\local\programs\python\python37-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.7\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
    _mysql.c
    MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.21.27702\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\MyUserName\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-install-z7x81g2q\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\MASTER~1\\AppData\\Local\\Temp\\pip-install-z7x81g2q\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\MASTER~1\AppData\Local\Temp\pip-record-z1mvci5v\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

Have you read it well ?...i assume that you have everything ... the Build tools, the MySQL Connector C 6.1...you even moved it to Program Files (x86)...so what it wrong...?? ...
Now take a closer look

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.21.27702\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -

I am pretty sure you saw it...STILL NO ?.... let me bold it for you

"-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -

mariadb
Well it can't be any stupidest than this ...the installer looks for mariadb includes and later libs Just go to the mariadb site and download the MariaDB C/C++ connector and install it...
Well its not over.. Goto to C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include and create folder mariadb...and copy paste the contents from the mariaDb connector installation include folder
again don't go way...go to C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib and do again the same drill for the lib folder
so you should have

C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb  

C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib\mariadb  

Now hit the pip3 install mysqlclient
and enjoy installing without a nag...the end

Successfully installed mysqlclient-1.4.2.post1