Issues installing MySQLdb with Python 3.6.5: Can't open 'mysql.h' - and Can't open : 'config-win.h': No such file or directory
Solution 1
Use the precompiled binary whl file from Cristoph Golke. It's far easier than setting up the complete dev environment to compile a single library.
Download the .whl file, then pip install <path to .whl>
inside the python environment you're using.
Solution 2
I got this error while installing mysqlclient in my Django project. _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\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe' failed with exit status 2
I have found workaround to fix this issue. The reason was to mysqlclient version mismatch according to your Python version
First, You can check python version
python --version
And then You can install mysqlclient version according to python version.
If python version is 3.7, then you can install mysqlclient==1.3.14 or directly download mysqlclient-1.3.14-cp37-cp37m-win_amd64.whl file.
If you python version is 3.6, then you can install mysqlclient==1.3.13 or directly download mysqlclient-1.3.13-cp36-cp36m-win_amd64.whl file.
nm6834
Updated on June 16, 2022Comments
-
nm6834 almost 2 years
I am trying to use mysql with python SQLAlchemy however python fails to install MySQL or even recognize it is installed. Below are the details:
I'm running this on Windows 10 64 bit and Anaconda Python 3.6.5
I downloaded MySQL through MAMP: Mac-Apace-MySQL-PHP https://www.mamp.info/en/
I have tried running my code on VSC and Jupyter.
-
If I try running the code
pip install mysqlclient
_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\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe' failed with exit status 2
-
I tried
pip install MySQL-python
but get_mysql.c _mysql.c(42): fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe' failed with exit status 2
-
I tried
pip install MySQLdb
and get:Collecting MySQLdb Could not find a version that satisfies the requirement MySQLdb (from versions: ) No matching distribution found for MySQLdb
I tried installing MySQL - from the actual Oracle website, did not work
I tried downloading the MySQL-connector to python: I get python v3.6 not found. we only support python using MSI.
I heave searched this issue on SoF but every issue is either outdated or custom geared towards that poster's case and I honestly would not know where to start. I've read that it may be a config issue to where python can't tell where MySQL is located and so I need to customize the path to it but I do not have the technical depth to meddle with that as I'm worried I may end up making it even worst.
I sincerely appreciate any input to this matter as I am truly in a bind and have no idea where to go from here.
-
tadman almost 6 yearsDo you have the development headers for MySQL? This is often a separate package and may not come with MAMP.
-
nm6834 almost 6 yearsNo please tell me more
-
tadman almost 6 yearsThat's where
mysql.h
and friends come from. On Linux/macOS this is straightforward, you just install the right package, but I'm not sure what the equivalent is for MAMP on Windows. The key is to find the "development headers" before attempting topip install
anything that depends on them. -
nm6834 almost 6 yearsI tried the development header: dev.mysql.com/downloads/installer
-
Alex R over 5 yearsPossible duplicate of Can't install mysql-python (newer versions) in Windows
-
Willie Cheng about 4 years
-
Jeevan Chaitanya about 3 yearsthis one worked perfectly after hours of searching.... thanks