2012-09-19 29 views
1

嗨,我已经安装了WAMP服务器(Mysql,apache,php),并且还单独安装了“Python”。现在我试图使用python代码连接到该数据库。Wamp Server和Python

这是我的Python代码:

#!C:\Python32\python.exe 
import sys 
import os 
import cgi 
import MySQLdb 
import cgitb 
import SecureDb 
cgitb.enable() 
print ("Content-type: text/plain\n\n"); 
conn= MySQLdb.connect(host = SecureDb.host ,user =SecureDb.user ,passwd=SecureDb.password ,db=SecureDb.database) 
cursor=conn.cursor() 
cursor.execute("select * from register where Name='Subburaj'") 
result=cursor.fetchall() 
cursor.close() 
conn.close() 

但是,这是否显示错误:

Traceback (most recent call last): 
    File "C:\Users\Ponmani\Desktop\test.cgi", line 5, in <module> 
    import MySQLdb 
    File "C:\Python32\lib\site-packages\MySQLdb\__init__.py", line 17, in <module> 
    from release import __version__, version_info, __author__ 
ImportError: No module named release 

如果有人过这样的问题来了,请帮我解决this.Thanks提前。

+0

回溯中的奇数行2与文件中的第2行不匹配。你确定你给我们的是'C:\ Users \ Ponmani \ Desktop \ test.cgi'的内容吗? –

+0

对不起大卫罗宾逊..现在你可以看到我编辑的帖子.. –

回答

1

你需要安装MySQLdb的模块

easy_install MySQL-python 
+0

我在哪里执行此命令? –

+0

在命令行提示符下。如果您尚未安装easy_install,请从http://pypi.python.org/pypi/setuptools – Rakesh

+0

下载并安装它,但这不适用于Windows。 –

2

MySQLdb的不来的蟒蛇。看来你必须先从here安装它。有一个可执行文件here,如果你使用的是Windows 32,但是它适用于python 2.7。如果你使用Python 3.2,它会变得更加困难。 Here's一个非官方的包应该为3.2工作。

编辑: 发布模块应该是mysqldb的一部分,我唯一的猜测是仍然有问题的安装。也许subforlders提取不正确。你应该尝试重新安装。

编辑:你也可以检查你是否有mysqldb目录中的release.py。如果你不这肯定是安装问题。

+0

感谢根..我已经安装了.. –

+0

@ prakash - 更新 – root

+0

根在该链接我不能看到任何可下载的文件? –