Windows x64安装MySQL-Python

1.安装 Microsoft Visual C++ Compiler Package for Python 2.7

下载链接

2.安装 MySQL Connector C 6.0.2

下载链接

3.下载 MySQL-python 1.2.5 源码包

下载链接

4.解压源码包后,修改 site.cfg 文件。

实际上,如果你是在32 位系统上部署,那么通过pip install 安装MySQL-python 1.2.5 只需进行上面的依赖包安装即可。
但在 64 位环境中,就会提示“Cannot open include file: ‘config-win.h’” 的错误。
原因就是 site.cfg 中写的 MySQL Connector C 为32 位版本。

原来的 site.cfg 文件内容如下:

# http://stackoverflow.com/questions/1972259/mysql-python-install-problem-using-virtualenv-windows-pip
# Windows connector libs for MySQL. You need a 32-bit connector for your 32-bit Python build.
connector = C:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2

修改为:

connector = C:\Program Files\MySQL\MySQL Connector C 6.0.2

5.运行 python setup.py install 即可安装完成。