"Cannot open include file: 'config-win.h': No such file or directory" while installing mysql-python

PythonWindowsVirtualenvPipMysql Python

Python Problem Overview


I'm trying to install mysql-python in a virtualenv using pip on windows. At first, I was getting the same error reported here, but the answer there worked for me too. Now I'm getting this following error:

_mysql.c(34) : Fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory

If I symlink (Win7) to my regular (not the virtualenv's) python's site-packages/MySQLdb dir I get

Error loading MySQLdb module: No module named _mysql

I'm rather at a loss here. Any pointers?

Python Solutions


Solution 1 - Python

All I had to do was go over to oracle, and download the MySQL Connector C 6.0.2 (newer doesn't work!) and do the typical install.

https://downloads.mysql.com/archives/c-c/

Be sure to include all optional extras (Extra Binaries) via the custom install, without these it did not work for the win64.msi

Once that was done, I went into pycharms, and selected the MySQL-python>=1.2.4 package to install, and it worked great. No need to update any configuration or anything like that. This was the simplest version for me to work through.

Hope it helps

Solution 2 - Python

The accepted solution no longer seems to work for newer versions of mysql-python. The installer no longer provides a site.cfg file to edit.

If you are installing mysql-python it'll look for C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include. If you have a 64-bit installation of MySQL, you can simply invoke:

  1. mklink /d "C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" "C:\Program Files\MySQL\MySQL Connector C 6.0.2\include"
  2. Run pip install mysql-python
  3. Delete the symbolic link created in step 1

Solution 3 - Python

Update for mysql 5.5 and config-win.h not visible issue

In 5.5 config-win. has actually moved to Connector separate folder in windows. i.e. smth like:

C:\Program Files\MySQL\Connector C 6.0.2\include

To overcome the problem one need not only to download "dev bits" (which actually connects the connector) but also to modify mysqldb install scripts to add the include folder. I've done a quick dirty fix as that.

site.cfg:

# Windows connector libs for MySQL.
connector = C:\Program Files\MySQL\Connector C 6.0.2

in setup_windows.py locate the line

include_dirs = [ os.path.join(mysql_root, r'include') ]:

and add:

include_dirs = [ os.path.join(options['connector'], r'include') ]

after it.

Ugly but works until mysqldb authors will change the behaviour.


Almost forgot to mention. In the same manner one needs to add similar additional entry for libs:

library_dirs = [ os.path.join(options['connector'], r'lib\opt') ]

i.e. your setup_windows.py looks pretty much like:

...
library_dirs = [ os.path.join(mysql_root, r'lib\opt') ]
library_dirs = [ os.path.join(options['connector'], r'lib\opt') ]
libraries = [ 'kernel32', 'advapi32', 'wsock32', client ]
include_dirs = [ os.path.join(mysql_root, r'include') ]
include_dirs = [ os.path.join(options['connector'], r'include') ]
extra_compile_args = [ '/Zl' ]
...

Solution 4 - Python

The accepted answer is out of date. Some of the suggestions were already incorporated in the package, and I was still getting the error about missing config-win.h & mysqlclient.lib.

  • Install mysql-connector-c-6.0.2-win32.msi

    > There's a zip file for the conenctor too but that didn't work because > mysqlclient.lib is in lib directory whereas the installer expects > it in lib/opt. Instead of hacking site.cfg or setup_windows.py, the > msi does the job.

  • pip install mysql-python

P.S. Since I don't use MySQL anymore, my answer may be out of date as well.

Solution 5 - Python

I know this post is super old, but it is still coming up as the top hit in google so I will add some more info to this issue.

I was having the same problems as OP but none of the suggested answers seemed to work for me. Mainly because "config-win.h" didn't exist anywhere in the connector install folder.

I was using the latest Connector C 6.1.6 as that was what was suggested by the MySQL installer.

This however doesn't seem to be supported by the latest MySQL-python package (1.2.5). When trying to install it I could see that it was explicitly looking for C Connector 6.0.2.

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

So by installing this version from https://dev.mysql.com/downloads/file/?id=378015 the python package installed without any problem.

Solution 6 - Python

Most probably the answer is to install MySQL Developer Build and selecting "C headers\libs" option during configuration. (as reported in this entry: Building MySQLdb for Python on Windows on rationalpie.wordpress.com)

Maybe even better solution is to install a precompiled build: http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe

Solution 7 - Python

If pip fails to install "MySQLdb", a workaround is to download and install it on your machine first from this link

http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

then copy all MySQL* and _mysql* files and directories from your system Python to your Virtualenv dir:

c:\Python27\Lib\site-packages (or similar path to your system Python) to c:\my_virtenv\Lib\site-packages (path to your virtualenv)

Solution 8 - Python

Well, if you are still having the problem, you can download the installer from http://code.google.com/p/soemin/downloads/detail?name=MySQL-python-1.2.3.win32-py2.7.exe

Solution 9 - Python

I had a lot of headache with MySQLdb too.

Why not use the official MysQL Python Connector?

easy_install mysql-connector-python

Or you can download it from here: http://dev.mysql.com/downloads/connector/python/

Documentation: http://dev.mysql.com/doc/refman/5.5/en/connector-python.html

Solution 10 - Python

Installing dev bits for mysql got rid of the config-win.h error I was having, and threw another. Failed to load and parse the manifest. The system cannot find the file specified. I found the answer to my problem in this post: http://www.fuyun.org/2009/12/install-mysql-for-python-on-windows/.

I copied the file 'C:\Python26\Lib\distutils\msvc9compiler.py` into my virtualenv, made the edit suggested in the above link, and things are working fine.

Solution 11 - Python

Simplest working solution:

Download the MySQL Connector C 6.0.2 from below link and Install.

http://dev.mysql.com/downloads/connector/c/6.0.html#downloads

After installing the MySQL Connector C 6.0.2, copy the folder "MySQL Connector C 6.0.2" from "C:\Program Files\MySQL" to "C:\Program Files (x86)\MySQL".

Then type

pip install MySQL-python

It will definitely work.

Solution 12 - Python

In my case, my fix was copying the folder created from mysql-connector-c-6.0.2-win32.msi (referenced from username buffer in a previous post), which is located at c:\Program Files\MySQL\MySQL Connector C 6.0.2 and creating a new path with Program Files (x86) and pasting the content there since the installation is not properly checking between 32-bit and 64-bit machines.

So, the new path is C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2. This is the path that the installer is looking to find, so I pasted the files there to help the installer to find the files, which was causing the error about missing config-win.h

Solution 13 - Python

Steps for Window10:

  • Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
  • Download the right version according to python version and hardware specs: for my case, mysqlclient‑1.4.2‑cp37‑cp37m‑win32.whl works for python3.7 and Intel CPU.
  • While your env is still activated, go to the download folder and run pip install mysqlclient-1.4.2-cp37-cp37m-win32.whl

Solution 14 - Python

Try ActivePython,

pypm -E C:\myvirtualenv install mysql-python

Solution 15 - Python

I did follow the answer from Bugagotti, And it does not work in my windows (Win7 64 bit, py27 and have mysql connector 6.1 installed) for mysql-python-1.2.5, so I made some even dirty changes inside mysql-python-1.2.5:

First, the site.cfg:

connector = C:\Program Files\MySQL\MySQL Connector C 6.1

Second, the _mysql.c :

#if defined(MS_WINDOWS)
#include <config-win.h>
#else
#include "my_config.h"
#endif

To:

#if 0 /*defined(MS_WINDOWS)*/
#include <config-win.h>
#else
#include "my_config.h"
#endif

And with these changes ,the config_win.h issue will gone, but there is still a link issue:

LINK : fatal error LNK1181: cannot open input file 'mysqlclient.lib'

For this, I changed the setup_windows.py:

library_dirs = [ os.path.join(connector, r'lib\vs9') ]  ## the original value was r'lib\opt'

Then it worked finally.

Solution 16 - Python

I followed Mingcai SHEN's method.

But in my case, I changed the connector to

connector = C:\Program Files\MySQL\MySQL Connector.C 6.1

And the library_dirs is changed to

library_dirs = [ os.path.join(connector, r'lib\vs10') ]

because I don't have a vs9 directory. It works, but I don't know why.

I have vs2012 installed, and the lib directory of the connector only has vs10 and vs11, in which vs11 doesn't work. The VCForPyhton27.mis I installed seems to support vs9.

Anyway, this works. And if you want to risk it, you can try.

Solution 17 - Python

Solution that worked for me on Windows: Install both the 32-bit and 64-bit versions of the MySQL Connector/C 6.0.2. Open Command Prompt and run:

pip install mysql-python

Solution 18 - Python

For me the following approach solved the issue (Python 3.5.2; mysqlclient 1.3.9):

  1. Dowload latest MySQL C Connector http://dev.mysql.com/downloads/connector/c/ (for me was Windows (x86, 64-bit), MSI Installer)
  2. Copy c:\Program Files\MySQL\MySQL Connector C 6.0.2\ directory to c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\
  3. Run pip install mysqlclient
  4. [optional] delete c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\

The issue here is only for x64 bit installation owners, since build script is trying to locate C connector includes in x86 program files directory.

Solution 19 - Python

building '_mysql' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
C:\Users\TimHuang\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_mysql.c /Fobuild\temp.win-amd64-2.7\Release\_mysql.obj /Zl
_mysql.c
_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory

If you see this when you try pip install mysql-python, the easiest way is to copy

C:\Program Files\MySQL\MySQL Connector C 6.0.2 to C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2

I tried to create the symbolic link but Windows keeps throwing me C:\WINDOWS\system32>mklink /d "C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" "C:\Program Files\MySQL\MySQL Connector C 6.0.2\include" The system cannot find the path specified.

Solution 20 - Python

If you are doing this in a virtual environment whether using Visual Studio or otherwise, try easy_install MySQL-python

Solution 21 - Python

  1. Download from this
  1. Then install this whl by pip installer. Shift + right click in Downloaded folder and choose Open powershell here. Then install using command: pip install package_name.whl

Solution 22 - Python

Download the version of Connector from https://dev.mysql.com/downloads/connector/c/6.0.html For my case I had installed 64 bit of connector and my python was 32 bit. So I had to copy MySQL from program files to Program Files(86)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsaturdayplaceView Question on Stackoverflow
Solution 1 - PythonKevin ManselView Answer on Stackoverflow
Solution 2 - PythonGiliView Answer on Stackoverflow
Solution 3 - PythonBugagottiView Answer on Stackoverflow
Solution 4 - PythonuserView Answer on Stackoverflow
Solution 5 - PythonjimmyView Answer on Stackoverflow
Solution 6 - PythonchodorowiczView Answer on Stackoverflow
Solution 7 - PythonDmitriyView Answer on Stackoverflow
Solution 8 - PythonEthanView Answer on Stackoverflow
Solution 9 - PythonYassine ElBadaouiView Answer on Stackoverflow
Solution 10 - PythonsaturdayplaceView Answer on Stackoverflow
Solution 11 - PythonGil BaggioView Answer on Stackoverflow
Solution 12 - PythonRyanView Answer on Stackoverflow
Solution 13 - PythonDavid PView Answer on Stackoverflow
Solution 14 - PythonSridhar RatnakumarView Answer on Stackoverflow
Solution 15 - PythonMingcai SHENView Answer on Stackoverflow
Solution 16 - PythonzijuexianshengView Answer on Stackoverflow
Solution 17 - PythonraulView Answer on Stackoverflow
Solution 18 - PythonDagazView Answer on Stackoverflow
Solution 19 - Pythontimbuntu2View Answer on Stackoverflow
Solution 20 - PythonSaher AhwalView Answer on Stackoverflow
Solution 21 - PythonJacky PhamView Answer on Stackoverflow
Solution 22 - PythonIshwar RimalView Answer on Stackoverflow