2

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.

nm6834
  • 99
  • 1
  • 2
  • 11
  • 1
    Do you have the development headers for MySQL? This is often a separate package and may not come with MAMP. – tadman Jun 30 '18 at 22:24
  • No please tell me more – nm6834 Jun 30 '18 at 22:36
  • 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. – tadman Jun 30 '18 at 22:38
  • I tried the development header: https://dev.mysql.com/downloads/installer/ – nm6834 Jun 30 '18 at 22:55
  • Possible duplicate of [Can't install mysql-python (newer versions) in Windows](https://stackoverflow.com/questions/37092125/cant-install-mysql-python-newer-versions-in-windows) – Alex R Sep 27 '18 at 00:54

8 Answers8

13

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.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
1

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.

Zhong Ri
  • 2,556
  • 1
  • 19
  • 23
0

Install the Mysql Connector/C and restart pip install mysqlclient. If your Visual C is properly installed it will work

Droopy
  • 1
0

Maybe you are opening something that uses the python process executing one of files need to be downloaded for installing (in my experience, I was opening Pycharm, and the process was using '_mysql.cp36-win_amd64.pyd' file)

Hope this helps someone

Leo Lucas
  • 15
  • 1
  • 9
0

None of the solutions here and elsewhere worked for me. Turns out an incompatible 32bit version of mysqlclient is being installed on my 64bit Windows 10 OS.

I had to uninstall my current Python 3.7 32bit, and reinstalled Python 3.7 64bit and everything is working fine now

Vyrnach
  • 119
  • 1
  • 9
0

For install mysqlclient you need to Visual C++ 2015 Build Tools. Use below link to download visualstudio tool. http://go.microsoft.com/fwlink/?LinkId=691126&fixForIE=.exe.

Now you need to set your visual studio path in path variable by using below command in commandline.

“setx path "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"”

Now you need to install mysqlclient by using below command “pip install mysqlclient”

If you found error like “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 14.0\VC\BIN\cl.exe' failed with exit status 2”

so you need to download .whl file for direct install, You can use below link to download as per your system compatibility.

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

“mysqlclient-1.4.2-cp37-cp37m-win32.whl” file work for me.

“pip install mysqlclient-1.4.2-cp37-cp37m-win32.whl”

Mysqlclient is install now!!

You need to change setting.py according to mysql

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'learnpython',
    'USER': 'nilesh',
    'PASSWORD': 'Radhe@12',
    'HOST': 'localhost',
    'PORT': 3306
}

}

Enjoy now Django is connect with mysql!! For more details "http://itfundasphp.blogspot.com/2019/06/django-connect-to-mysql.html"

Nilesh Gupta
  • 367
  • 1
  • 2
0

I've had the same issue. I simply downloaded python-64 installer and installed on my machine and choosed 64bit as interperter.

I didn't understand why 32bit python doesn't work here.

I hope this might be helpful.

0

pip install mysqlclient didn't worked for me

I tried pip install --only-binary :all: mysqlclient and worked like a charm

Govinda
  • 789
  • 7
  • 6