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
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)
Download from this
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:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
mysqlclient-1.4.2-cp37-cp37m-win32.whl
works for python3.7 and Intel CPU.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):
c:\Program Files\MySQL\MySQL Connector C 6.0.2\
directory to c:\Program Files (x86)\MySQL\MySQL Connector C 6.1\
pip install mysqlclient
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 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.
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:
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"
pip install mysql-python
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.
Source: Stackoverflow.com