当我使用web.py连接本地mysql时,会出现一些错误:
Traceback (most recent call last):
File "code.py", line 7, in <module>
db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
File "/Library/Python/2.6/site-packages/web.py-0.34-py2.6.egg/web/db.py", line 1078, in database
return _databases[dbn](**params)
File "/Library/Python/2.6/site-packages/web.py-0.34-py2.6.egg/web/db.py", line 928, in __init__
import MySQLdb as db
File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found. Did find:
/Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture
我的python代码如下:
import web
render = web.template.render('templates/')
urls = (
"/(.*)","index"
)
app = web.application(urls,globals())
db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
class index:
def GET(self):
todos = db.select('todo')
return render.index(todos)
if __name__=="__main__":app.run()
我的python版本是2.6.1
我该怎么办呢?
感谢
答案 0 :(得分:0)
您为Python安装的mysql
适配器已损坏或适用于其他架构。我不确定你是如何安装它的(或者这些东西在OSX上如何工作)。讨论安装的Here's a question。如果你做对了,它应该可以正常工作(假设凭证是正确的)。
答案 1 :(得分:0)
db = web.database(dbn ='mysql',db ='projefg9_emearmy_ps_erc',user ='root', PW = '管理员')
其中dbn - 你正在使用的数据库(对于mysql,它是“mysql”) db - 数据库名称 user - 数据库的用户名 pw - 数据库的密码