Building MySQLdb for Python on Windows
MySQLdb is perhaps the most widely used interface between python and MySQL. Sadly for the python developers on Windows, there are no official pre-built binaries for MySQLdb for window. You are expected to build for your own system using the scripts provided.
As almost always is the case, this path is fraught with problems. I have documented below the problems I ran into while building MySQLdb myself.
System:
- Win32 (XP)
- Microsoft Visual C++ compiler
- MySQL developer build: to install this make sure that you select the “C headers\libs” option on the installation configuration page (this usually is the first page of the wizard). If you do not have these components installed you will see errors like this: _mysql.c(34) : fatal error C1083: Cannot open include file: ‘config-win.h’: No such file or directory
error: command ‘”C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe”‘ failed with exit
status 2 - setuptools.py: get the installer from http://pypi.python.org/pypi/setuptools
Steps to install:
- open site.cfg and look for the line: registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0, update it for your version of MySQL, I changed it to registry_key = SOFTWARE\MySQL AB\MySQL Server 5.1
- run python setup.py build
- if you get error like this:
build\temp.win32-2.6\Release\_mysql.pyd.manifest : general error c1010070: Faile
d to load and parse the manifest. The system cannot find the file specified.
error: command ‘mt.exe’ failed with exit status 31As suggested here do the following:
- go to C:\Program Files\Python26\Lib\distutils or a similar path depending on where your target python version is installed
- open the file msvc9compiler.py and look for MANIFESTFILE, you should see the following line
ld_args.append(’/MANIFESTFILE:’ + temp_manifest) - Add another line just after this one
ld_args.append(’/MANIFEST’)
- run python setup.py bdist_wininst . Thus will give you an executable in the \dist directory, run this .exe file and get going!
本文详细介绍了在Windows系统中使用MySQLdb作为Python和MySQL之间的接口时遇到的问题及解决方案,包括安装步骤、配置和常见错误处理。
3247

被折叠的 条评论
为什么被折叠?



