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

Question:

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?

Asked By: saturdayplace

||

Answers:

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:Python26Libdistutilsmsvc9compiler.py` into my virtualenv, made the edit suggested in the above link, and things are working fine.

Answered By: saturdayplace

Most probably the answer is to install MySQL Developer Build and selecting “C headerslibs” 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

Answered By: chodorowicz

Try ActivePython,

pypm -E C:myvirtualenv install mysql-python
Answered By: Sridhar Ratnakumar

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 FilesMySQLConnector C 6.0.2include

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 FilesMySQLConnector 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'libopt') ]

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

...
library_dirs = [ os.path.join(mysql_root, r'libopt') ]
library_dirs = [ os.path.join(options['connector'], r'libopt') ]
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' ]
...
Answered By: Bugagotti

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

Answered By: Ethan

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

Answered By: Yassine ElBadaoui

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.

Answered By: Kevin Mansel

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)MySQLMySQL Connector C 6.0.2include. If you have a 64-bit installation of MySQL, you can simply invoke:

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

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.

Answered By: user

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:Python27Libsite-packages (or similar path to your system Python) to
c:my_virtenvLibsite-packages (path to your virtualenv)

Answered By: Dmitriy

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 FilesMySQLMySQL 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)MySQLMySQL 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

Answered By: Ryan

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 FilesMySQLMySQL 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'libvs9') ]  ## the original value was r'libopt'

Then it worked finally.

Answered By: Mingcai SHEN

I followed Mingcai SHEN’s method.

But in my case, I changed the connector to

connector = C:Program FilesMySQLMySQL Connector.C 6.1

And the library_dirs is changed to

library_dirs = [ os.path.join(connector, r'libvs10') ]

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.

Answered By: zijuexiansheng

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)MySQLMySQL Connector C 6.0.2include"

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

Answered By: jimmy

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
Answered By: raul

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

Answered By: Saher Ahwal

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 FilesMySQLMySQL Connector C 6.0.2 directory to c:Program Files (x86)MySQLMySQL Connector C 6.1
  3. Run pip install mysqlclient
  4. [optional] delete c:Program Files (x86)MySQLMySQL 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.

Answered By: Dagaz
  1. Download from this

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

Answered By: Jacky Pham

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 FilesMySQL” to “C:Program Files (x86)MySQL”.

Then type

pip install MySQL-python

It will definitely work.

Answered By: Gil Baggio
building '_mysql' extension
creating buildtemp.win-amd64-2.7
creating buildtemp.win-amd64-2.7Release
C:UsersTimHuangAppDataLocalProgramsCommonMicrosoftVisual C++ for Python9.0VCBinamd64cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:Program Files (x86)MySQLMySQL Connector C 6.0.2include" -Ic:python27include -Ic:python27PC /Tc_mysql.c /Fobuildtemp.win-amd64-2.7Release_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 FilesMySQLMySQL Connector C 6.0.2
to C:Program Files (x86)MySQLMySQL Connector C 6.0.2

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

Answered By: timbuntu2

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)

Answered By: Ishwar Rimal

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
Answered By: David P