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

119,279

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:

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

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.

Share:
119,279
saturdayplace
Author by

saturdayplace

Updated on July 05, 2022

Comments

  • saturdayplace
    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
    John about 14 years
    Quick 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
    rocketmonkeys over 13 years
    Can you install the binary into a virtualenv? When I tried, it only gave me the option of my system python installation.
  • chodorowicz
    chodorowicz over 13 years
    No, 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
    Dave over 13 years
    I 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
    Shrike over 13 years
    So 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
    rocketmonkeys over 13 years
    I'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
    saturdayplace over 13 years
    This 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
    Mohamed Faramawi over 12 years
    Thanks a bunch it didn't work for me till i've done what you listed here
  • laurent
    laurent over 11 years
    I used this exe file with easy_install under virtualenv and it works well under windows XP
  • Piotr Dobrogost
    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
    Tayla Wilson about 11 years
    as 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
    Nicola Peluchetti about 11 years
    @fastmultiplication i don't have that folder, what should i install?
  • Shailen
    Shailen almost 11 years
    What are "dev bits? Google doesn't even know what are these :(
  • saturdayplace
    saturdayplace almost 11 years
    @shailenTJ - See chodorowicz's answer below about installing the MySQL developer build.
  • Shailen
    Shailen over 10 years
    @laurent, You Sir, deserve a medal.
  • Karthic Raghupathi
    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
    Ryan over 10 years
    Is 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
    Ryan over 10 years
    It 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
    User almost 10 years
    Thanks Kevin! I knew there must have been an easier way! Worked great.
  • turingcomplete
    turingcomplete over 9 years
    Dude, 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
    Omer over 9 years
    This 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
    Charlie over 9 years
    I 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
    Matheus Santos almost 9 years
    Nice. 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
    Zgr3doo almost 9 years
    symbolic 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
    Prasad DLV almost 9 years
    After 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
    canadiancreed almost 9 years
    This requires python v2.6, so for anyone not using that, you're SOL
  • canadiancreed
    canadiancreed almost 9 years
    This solution no longer works. Attempted all four possibilities and all four failed.
  • kmarsh
    kmarsh over 8 years
    If 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
    mtoloo over 8 years
    It was easiest solution for me. Don't forget to use mysqlconnector API: engine = create_engine('mysql+mysqlconnector://scott:tiger@localhost/‌​foo')
  • jarmod
    jarmod over 8 years
    This 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
    Olivier Pons over 8 years
    For 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
    Olivier Pons over 8 years
    This 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
    twasbrillig almost 8 years
    This solution worked the best for me, in both Python 2 and 3.
  • danio
    danio almost 8 years
    Currently this only supports python up to 3.4
  • Eric Lee
    Eric Lee over 7 years
    Make 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
    coder.in.me over 7 years
    Works on Windows 10. I had to create a symbolic link to lib folder in addition to include folder.
  • JoKr
    JoKr over 7 years
    Current 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
    Ankur Agarwal over 7 years
    This worked for me since I have python 2.7 installed. Thanks!
  • आनंद
    आनंद about 7 years
    Thank you my lord! This is the only option that worked for me after searching the whole damn internet for 14 hours.
  • Gleb Sevruk
    Gleb Sevruk about 7 years
    Thanks that worked, i did download x86 and was able to install
  • AN88
    AN88 about 7 years
    Where does one find mysqldb install scripts when installing through pip in a virtualenv?
  • BrandonSun
    BrandonSun almost 7 years
    As 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
    Nicojo over 6 years
    Quick 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
    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
    Code_Worm over 5 years
    thanks 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
    Gil Baggio over 5 years
    Happy to help you bro. Cheers! @Code_Worm
  • Abhishek L
    Abhishek L almost 5 years
    Thanks.this post worked for me. Python 2.7 mysql-python-1.2.5
  • vesperto
    vesperto about 2 years
    Most 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.