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

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?

This question is related to python windows virtualenv pip mysql-python

The answer is


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


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


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)


  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


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

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.


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


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


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

Try ActivePython,

pypm -E C:\myvirtualenv install mysql-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


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.


If you are doing this in a virtual environment whether using Visual Studio or otherwise, try easy_install MySQL-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)


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.


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.


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.


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.


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

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.


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to windows

"Permission Denied" trying to run Python on Windows 10 A fatal error occurred while creating a TLS client credential. The internal error state is 10013 How to install OpenJDK 11 on Windows? I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? git clone: Authentication failed for <URL> How to avoid the "Windows Defender SmartScreen prevented an unrecognized app from starting warning" XCOPY: Overwrite all without prompt in BATCH Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory how to open Jupyter notebook in chrome on windows Tensorflow import error: No module named 'tensorflow'

Examples related to virtualenv

How to setup virtual environment for Python in VS Code? Conda version pip install -r requirements.txt --target ./lib What is the purpose of "pip install --user ..."? What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc? ImportError: No module named 'encodings' how to specify new environment location for conda create Use virtualenv with Python with Visual Studio Code in Ubuntu Is it ok having both Anacondas 2.7 and 3.5 installed in the same time? How to uninstall a package installed with pip install --user Unable to install boto3

Examples related to pip

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? What is the meaning of "Failed building wheel for X" in pip install? Could not install packages due to an EnvironmentError: [Errno 13] How do I install Python packages in Google's Colab? Conda version pip install -r requirements.txt --target ./lib pip: no module named _internal AttributeError: Module Pip has no attribute 'main' Error after upgrading pip: cannot import name 'main'

Examples related to mysql-python

mysql-python install error: Cannot open include file 'config-win.h' Python 3.4.0 with MySQL database ImportError: No module named MySQLdb Install mysql-python (Windows) IndexError: tuple index out of range ----- Python cursor.fetchall() vs list(cursor) in Python How to insert pandas dataframe via mysqldb into database? Visibility of global variables in imported modules Replacing Pandas or Numpy Nan with a None to use with MysqlDB mysql_config not found when installing mysqldb python interface