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?
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.
# 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') ]:
include_dirs = [ os.path.join(options['connector'], r'include') ]
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' ] ...
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.
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
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:
mklink /d "C:Program Files (x86)MySQLMySQL Connector C 6.0.2include" "C:Program FilesMySQLMySQL Connector C 6.0.2include"
pip install mysql-python
- Delete the symbolic link created in step 1
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.
There’s a zip file for the conenctor too but that didn’t work because
libdirectory whereas the installer expects
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.
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.
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
If pip fails to install “MySQLdb”, a workaround is to download and install it on your machine first from this link
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)
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