Building MySQLdb for Python on Windows

 

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:

  1. 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
  2. run python setup.py build
  3. 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 31

    As 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’)
  4. run python setup.py bdist_wininst . Thus will give you an executable in the \dist directory, run this .exe file and get going!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值