免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1247 | 回复: 0
打印 上一主题 下一主题

Install MySQL for Python (MySQLdb) on Windows [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-19 13:55 |只看该作者 |倒序浏览

It took me quite a while to figure out how to build and install MySQL for Python (MySQLdb) on Windows. I’d better write it down.

There is no binary distribution of MySQLdb for Python 2.6 on Windows. I have to build it from the source. My environment is Windows XP. MySQL 5.1. Python 2.6 (windows version, not cygwin), and MySQL-python-1.2.3c1. Also, I have Microsoft Visual C++ 2008 Express Edition (Microsoft Visual Studio 9.0) installed, which is required to compile the C code in MySQL-python.

First of all, install Python setuptools, if you haven’t installed it. It is required in MySQL-python setup.py. I also added C:\Python26\Scripts into environment PATH, where easy_install is installed.

Then, make sure you have MySQL Developer Components installed. Download MySQL msi installer version, select “Developer Components” in Custom Setup. It will install C:\Program Files\MySQL\MySQL Server 5.1\include, lib\debug and lib\opt for you. They are not installed by default.

Uncompress MySQL-python-1.2.3c1.tar.gz into a directory. Open a command window (cmd), change to the directory.

Try to run,

setup.py build

I got this error in setup_windows.py:

in get_config
serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_key'])
WindowsError: [Error 2] The system cannot find the file specified

So I edited site.cfg, changed the MySQL version from 5.0 to 5.1 (since I am using 5.1)

registry_key = SOFTWARE\MySQL AB\MySQL Server 5.1

You can use regedit to check which version you are using. It is specified at: HKEY_LOCAL_MACHINE/SOFTWARE/MySQL AB/MySQL Server 5.1.

Now try to build it again. I got this error:

build\temp.win32-2.6\Release\_mysql.pyd.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find  the file specified.
error: command ‘mt.exe’ failed with exit status 31

To fix this problem, go to C:\Python26\Lib\distutils, edit msvc9compiler.py, search for ‘MANIFESTFILE’, you will find the following line

ld_args.append(‘/MANIFESTFILE:’ + temp_manifest)

Then append the following line after the above line,

ld_args.append(‘/MANIFEST’)

Then go back to run “setup.py build”, it will succeed. Finally, run

setup.py install

Test it in python

>>> import MySQLdb
>>>

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP