"Cannot open include file: 'config-win.h': No such file or directory" while installing mysql-python
Solution 1
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 2
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 3
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:
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
Solution 4
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 inlib
directory whereas the installer expects it inlib/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
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.
saturdayplace
Updated on July 05, 2022Comments
-
saturdayplace almost 2 years
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?
-
John about 14 yearsQuick question about "Installing dev bits for mysql got rid of the config-win.h error". What are "dev bits" and where can I get them? =) I'm having a similar issue.
-
rocketmonkeys over 13 yearsCan you install the binary into a virtualenv? When I tried, it only gave me the option of my system python installation.
-
chodorowicz over 13 yearsNo, I haven't tried. Here you can find a whole set of precompiled MySQLdb packages for Windows - maybe one them will work for you codegood.com/archives/4
-
Dave over 13 yearsI havent been able to do this in a virtualenv (well buildout but yeah). I also tried with lower versions (1.2.1, 1.2.2) without any success. Its a dependency on an app of mine so i would really like to see a more robust solution. I submitted a bug report here sourceforge.net/tracker/…
-
Shrike over 13 yearsSo do I. I've done mySql 5.5 complete installation. fixed site.cfg. But still getting the error: _mysql.c(34) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
-
rocketmonkeys over 13 yearsI'm reinstalling my whole python dev setup, and I'm stuck at this point. Where in the world can I find the "config-win.h" file???
-
saturdayplace over 13 yearsThis is covered in the link above: "Download MySQL msi installer version, select “Developer Components” in Custom Setup. These aren't installed by default."
-
Mohamed Faramawi over 12 yearsThanks a bunch it didn't work for me till i've done what you listed here
-
laurent over 11 yearsI used this exe file with easy_install under virtualenv and it works well under windows XP
-
Piotr Dobrogost over 11 years@Rocketmonkeys Yes, you can install binary into a virtualenv - see Can I install Python windows packages into virtualenvs?
-
Tayla Wilson about 11 yearsas of mysql-python 1.2.4, the default site.cfg has already been updated to reflect this comment. However, the default site.cfg is for 64 bit windows, so the path to the connector will be wrong on 32 bit. Remove (x86) and remove "MySQL" from "MySQL Connector C 6.0.2"
-
Nicola Peluchetti about 11 years@fastmultiplication i don't have that folder, what should i install?
-
Shailen almost 11 yearsWhat are "dev bits? Google doesn't even know what are these :(
-
saturdayplace almost 11 years@shailenTJ - See chodorowicz's answer below about installing the MySQL developer build.
-
Shailen over 10 years@laurent, You Sir, deserve a medal.
-
Karthic Raghupathi over 10 years+1 By far the simplest answer to this problem. A word of caution, select the appropriate architecture (x86/64bit) of the driver.
-
Ryan over 10 yearsIs this for version 3.3 as well? I did as you mentioned by downloading and installing the msi and then pip script, but I'm still getting the error in pip about config-win.h missing.
-
Ryan over 10 yearsIt looks like in my case, I see in the installation error C:\program files (x86). I use Windows 32-bit which does not use "(x86)" in the path. This is I think why the error is happening for me. Only problem is that I don't know where the file is located in order to correct this path setting.
-
User almost 10 yearsThanks Kevin! I knew there must have been an easier way! Worked great.
-
turingcomplete over 9 yearsDude, you are a life saver. I've been pulling on my hair for a while because of this error, I tried all other solutions which were more complicated. Thanks for providing such a simple solution.
-
Omer over 9 yearsThis is the right idea for a solution, however it didn't work for me. To solve the issue I copied the directory C:\Program Files\MySQL\MySQL Connector C 6.0.2\ to C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\. This solved the issue for me
-
Charlie over 9 yearsI had to install the connector for x64 and move the MySql folder from the 'Program Files' to the 'Program Files (x86)' directory since that's where the build script was looking for it
-
Matheus Santos almost 9 yearsNice. I installed the x64 version but did not worked. Then I followed your advice and installed the x86 and voilà! I'm using Python 3.4.3 and runned
pip install mysql-python
and it works. ;-) -
Zgr3doo almost 9 yearssymbolic link approach is good but it must be wider as there is more files required thus instead of @Gili symbolic link use this mklink /d "C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2" "C:\Program Files\MySQL\MySQL Connector C 6.0.2"
-
Prasad DLV almost 9 yearsAfter installing the MySQL Connector C 6.0.2, I tried "pip install MySQL-python". It still showed the same error. Then I copied the folder "MySQL Connector C 6.0.2" from "C:\Program Files\MySQL" to "C:\Program Files (x86)\MySQL" and it worked perfectly !!
-
canadiancreed almost 9 yearsThis requires python v2.6, so for anyone not using that, you're SOL
-
canadiancreed almost 9 yearsThis solution no longer works. Attempted all four possibilities and all four failed.
-
kmarsh over 8 yearsIf you've made it this far, you probably realize all this won't work. Besides no one caring to give the command for "dev bits", missing blog references, and the fact site.cfg and windows_setup.py probably doesn't exist in your default Python27 install, if you push past all this it still doesn't work. Ignore all above and go to kevin.mansel's answer below.
-
mtoloo over 8 yearsIt was easiest solution for me. Don't forget to use
mysqlconnector
API:engine = create_engine('mysql+mysqlconnector://scott:tiger@localhost/foo')
-
jarmod over 8 yearsThis works OK for include files but not for lib files. You can't just symlink the 32-bit lib folder to the 64-bit equivalent. It's probably better to simply install both the 32-bit and 64-bit SQL Connector packages independently, rather than symlink anything.
-
Olivier Pons over 8 yearsFor your information
MySQL Connector C 6.1
doesn't have the required file.MySQL Connector C 6.0.2
has it. So you have to choose a old version on the MySQL website... -
Olivier Pons over 8 yearsThis doesn't work at all. You need to download & install only the 32 bits version. Two hours lost in Windows. 3s install on Linux. What a shame.
-
twasbrillig almost 8 yearsThis solution worked the best for me, in both Python 2 and 3.
-
danio almost 8 yearsCurrently this only supports python up to 3.4
-
Eric Lee over 7 yearsMake sure you download the 32bit version of the connector. With the 32 bit connector, it will work with MySQL-python==1.2.5
-
coder.in.me over 7 yearsWorks on Windows 10. I had to create a symbolic link to
lib
folder in addition toinclude
folder. -
JoKr over 7 yearsCurrent version of MySQL-python (1.2.5) will not work with latest 6.1 connectors that MySQL installer will install. Make sure to install 6.0.2. connector.
-
Ankur Agarwal over 7 yearsThis worked for me since I have python 2.7 installed. Thanks!
-
आनंद about 7 yearsThank you my lord! This is the only option that worked for me after searching the whole damn internet for 14 hours.
-
Gleb Sevruk about 7 yearsThanks that worked, i did download x86 and was able to install
-
AN88 about 7 yearsWhere does one find mysqldb install scripts when installing through pip in a virtualenv?
-
BrandonSun almost 7 yearsAs of today (2017/7/2), this is the only option that worked for me on Win10 x64, with Python 2.7. I have tried the connector 6.1, but obviously it does not work.
-
Nicojo over 6 yearsQuick comment to say that in November 2017, you still need version 6.0.2 to work with MySQL-python 1.2.5. And you still need to copy over from Program Files to Program Files (x86) if you choose the 64bit version.
-
Umair Ayub about 6 years@Omer your suggestion installed it but when I run my code it still says no module named MySQLdb
-
Code_Worm over 5 yearsthanks man I had tried every thing and nothing worked but when I copied my 'MySQL Connector C' directory from program files into program files (x86) the problem solved you saved my day thank you again
-
Gil Baggio over 5 yearsHappy to help you bro. Cheers! @Code_Worm
-
Abhishek L almost 5 yearsThanks.this post worked for me. Python 2.7 mysql-python-1.2.5
-
vesperto about 2 yearsMost voted answer didn't work for me (using Python 2.7), this one moved me along to the next error which seems to stem from the fact i'm using MSYS Python which may be 64 bit instead of the required 32 bit. Yay.