Install Mysql-Python on Windows

本文提供了一个详细的指南,介绍如何在Windows环境下安装MySQLdb模块。包括安装setuptools、MySQL 5.1、Microsoft Visual Studio C++ Express 2008等前置步骤,并解决了可能出现的错误,如manifest文件加载失败的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

收入两个安装关于安装MySQLdb的URL

[url]http://stackoverflow.com/questions/645943/mysql-for-python-in-windows[/url]

As Python newbie learning the Python ecosystem I've just completed this.

Install setuptools instructions

Install MySQL 5.1. Download the 97.6MB MSI from here You can't use the essentials version because it doesnt contain the C libraries.
Be sure to select a custom install, and mark the development tools / libraries for installation as that is not done by default. This is needed to get the C header files.
You can verify you have done this correctly by looking in your install directory for a folder named "include". E.G C:\Program Files\MySQL\MySQL Server 5.1\include. It should have a whole bunch of .h files.

Install Microsoft Visual Studio C++ Express 2008 from here This is needed to get a C compiler.

Open up a command line as administrator (right click on the Cmd shortcut and then "run as administrator". Be sure to open a fresh window after you have installed those things or your path won't be updated and the install will still fail.

From the command prompt:

easy_install -b C:\temp\sometempdir mysql-python

That will fail - which is OK.

Now open site.cfg in your temp directory C:\temp\sometempdir and edit the "registry_key" setting to:

registry_key = SOFTWARE\MySQL AB\MySQL Server 5.1

now CD into your temp dir and:

python setup.py clean

python setup.py install

You should be ready to rock!

Here is a super simple script to start off learning the Python DB API for you - if you need it.

[url]http://hi.baidu.com/koflance/blog/item/78ae37f90f66c615a9d311f3.html[/url]

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 >>>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值