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

15,128

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.

Share:
15,128
nm6834
Author by

nm6834

Updated on June 16, 2022

Comments

  • nm6834
    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:

    1. I'm running this on Windows 10 64 bit and Anaconda Python 3.6.5

    2. I downloaded MySQL through MAMP: Mac-Apace-MySQL-PHP https://www.mamp.info/en/

    3. I have tried running my code on VSC and Jupyter.

    4. 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

    5. 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

    6. 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

    7. I tried installing MySQL - from the actual Oracle website, did not work

    8. 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
      tadman almost 6 years
      Do you have the development headers for MySQL? This is often a separate package and may not come with MAMP.
    • nm6834
      nm6834 almost 6 years
      No please tell me more
    • tadman
      tadman almost 6 years
      That'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 to pip install anything that depends on them.
    • nm6834
      nm6834 almost 6 years
      I tried the development header: dev.mysql.com/downloads/installer
    • Alex R
      Alex R over 5 years
  • Willie Cheng
    Willie Cheng about 4 years
  • Jeevan Chaitanya
    Jeevan Chaitanya about 3 years
    this one worked perfectly after hours of searching.... thanks