"Cannot open include file:" config-win.h ": no such file or directory" when installing mysql-python

I am trying to install mysql-python in virtualenv using pip in windows. At first I got the same error here , but the answer there worked for me too. Now I get the following error:

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

If I link (Win7) to my regular (non-virtual) python site-packages / MySQLdb file, I get

 Error loading MySQLdb module: No module named _mysql 

I'm out of order here. Any pointers?

+69
python windows pip mysql-python virtualenv
Dec 29 '09 at 0:13
source share
22 answers

Update for mysql 5.5 and config-win.h no problem visible

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

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

To overcome this problem, you need to not only download the "dev bits" (which actually connects the connector), but also modify the mysqldb installation scripts to add the include folder. I made a quick dirty fix.

site.cfg:

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

in setup_windows.py find the line

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

and add:

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

after him.

Horrible, but it works until the mysqldb authors change the behavior.




Almost forgot to mention. In the same way, add a similar additional entry for libs:

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

i.e. your setup_windows.py looks something like this:

 ... 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' ] ... 
+17
Apr 16 2018-11-11T00:
source share
— -

All I had to do was go to oracle, download MySQL Connector C 6.0.2 (the newer version doesn’t work!) And complete the normal installation.

old link (page not found)

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

new link

https://downloads.mysql.com/archives/cc/

Be sure to include all the extra add-ons (Extra Binaries) through the custom installation, without them this would not work for win64.msi

Once this was done, I went into pycharms and chose the MySQL-python> = 1.2.4 package to install, and it worked perfectly. No need to update the configuration or anything like that. This was the easiest version for me.

Hope help

+86
May 18 '13 at
source share

The accepted solution no longer works for newer versions of mysql-python. The installer no longer provides the site.cfg file for editing.

If you install mysql-python, it will look for C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include . If you have a 64-bit MySQL installation, you can simply call:

  • 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"
  • Run pip install mysql-python
  • Delete the symbolic link created in step 1
+24
Aug 09 '13 at 6:29
source share

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

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

    There is also a zip file for conenctor, but this did not work, because mysqlclient.lib is in the lib directory, while the installer expects this in lib/opt . Instead of hacking site.cfg or setup_windows.py, msi does the job.

  • pip install mysql-python

PS Since I no longer use MySQL, my answer may also be deprecated.

+15
Sep 27 '13 at 17:19
source share

I know this post is super old, but it still fits as the best hit on Google, so I will add more information to this problem.

I had the same problems as the OP, but none of the suggested answers worked for me. Mostly because "config-win.h" did not exist anywhere in the connector installation folder.

I used the latest Connector C 6.1.6, as suggested by the MySQL installer.

This, however, does not seem to be supported by the latest MySQL-python package (1.2.5). When I tried to install it, I could see that it was clearly looking for C Connector 6.0.2.

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

So, installing this version from the https://dev.mysql.com/downloads/file/?id=378015 python package is no problem.

+10
Aug 09 '16 at 8:55 on
source share

Most likely, the answer is to install the MySQL Developer Build and select the "C headers \ libs" option during configuration. (as reported in this post: Creating MySQLdb for Python on Windows at rationalpie.wordpress.com)

Perhaps even the best solution is to install a precompiled assembly: http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe

+7
Jan 26 '10 at 19:32
source share

If pip cannot install "MySQLdb", the workaround is to first download and install it on your computer from this link

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

then copy all the MySQL * and _mysql * files and directories from system Python to the Virtualenv directory:

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

+5
Dec 07 '13 at 0:07
source share

Well, if you still have a 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

+4
Jul 17 2018-11-11T00:
source share

I also had a big headache with MySQLdb.

Why not use the official MysQL Python Connector?

 easy_install mysql-connector-python 

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

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

+4
Jan 03 '13 at 2:50
source share

Setting the dev bit for mysql got rid of the config-win.h error that I had and threw another one. 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` to my virtualenv, did the editing suggested in the link above and everything works fine.

+3
Dec 29 '09 at 15:51
source share

The simplest working solution:

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

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

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

Then enter

 pip install MySQL-python 

This will definitely work.

+3
Sep 11 '17 at 19:42 on
source share

In my case, my fix copied a folder created from mysql-connector-c-6.0.2-win32.msi (the link from the username buffer in the previous message), which is located in the c: \ Program Files \ MySQL \ MySQL Connector C 6.0 directory .2 and creating a new path with program files (x86) and pasting the contents there, since the installation does not verify proper validation between 32-bit and 64-bit machines.

So, the new way 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 inserted files there to help the installer find the files, which caused an error in the absence of config-win.h

+2
Dec 08 '13 at 21:24
source share

Try ActivePython ,

 pypm -EC:\myvirtualenv install mysql-python 
+1
Mar 22 '11 at 22:21
source share

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

First, site.cfg:

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

Secondly, _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 problem will disappear, but there is still a problem with the channel:

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

To do this, I changed setup_windows.py:

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

Then he worked at last.

+1
Mar 28 '14 at 2:39
source share

I followed the Mingcai SHEN method.

But in my case, I replaced the connector with

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

And library_dirs changed to

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

because I do not have a vs9 directory. It works, but I don’t know why .

I have vs2012 installed, and the lib directory on the connector has only vs10 and vs11 , in which vs11 does not work. Installed VCForPyhton27.mis seems to support vs9 .

In any case, this works. And if you want to take a chance, you can try.

+1
Dec 27 '14 at 22:07
source share

The solution that worked for me on Windows : install both 32 bit and 64 bit versions of MySQL Connector / C 6.0 0.2 . Open Command Prompt and run:

 pip install mysql-python 
+1
07 Oct '16 at 20:43
source share

The following approach was solved for me (Python 3.5.2; mysqlclient 1.3.9):

  • Download the latest MySQL C Connector http://dev.mysql.com/downloads/connector/c/ (for me there was Windows (x86, 64-bit), the MSI installer)
  • Copy the directory c:\Program Files\MySQL\MySQL Connector C 6.0.2\ to c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\
  • Run pip install mysqlclient
  • [optional] delete c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\

The problem here is only for owners of the 64-bit installation, as the build script tries to find the C connector contained in the x86 program file directory.

+1
Jan 10 '17 at 21:06
source share
 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 - C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2

I tried to create a symbolic link, but Windows continues to give 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.

+1
Apr 13 '18 at 0:00
source share

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

0
Oct 28 '16 at 5:13
source share
0
Aug 20 '17 at 16:08
source share

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

0
Apr 25 '18 at 16:42
source share

Steps for Window10:

  • Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
  • Download the correct version according to the Python version and hardware specifications: for my case mysqlclient‑1.4.2‑cp37‑cp37m‑win32.whl works for python3.7 and Intel processors.
  • While your env is still activated, go to the download folder and run pip install mysqlclient-1.4.2-cp37-cp37m-win32.whl
0
Apr 02 '19 at 19:47
source share



All Articles