web.py连接mysql错误
当我使用 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
我该如何修复它?
谢谢
when i use web.py to connect local mysql, some error show:
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
my python code like this:
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()
my python version is 2.6.1
how could i fix it ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您为 Python 安装的
mysql
适配器已损坏或适用于不同的体系结构。我不确定你是如何安装它的(或者这些东西在 OSX 上如何工作)。 这是一个讨论安装的问题。如果你做对了,它应该可以正常工作(假设凭据正确)。The
mysql
adaptor you've installed for Python is corrupt or for a different architecture. I'm not sure how you've installed it (or how these things work on OSX). Here's a question that discusses the installation. If you get that right, it should work fine (assuming that the credentials are correct).db = web.database(dbn='mysql', db='projefg9_emearmy_ps_erc', user='root',
pw='admin')
其中 dbn -- 您正在使用的数据库(对于 mysql,它是“mysql”)
db——数据库名称
user -- 数据库的用户名
pw -- 数据库的密码
db = web.database(dbn='mysql', db='projefg9_emearmy_ps_erc', user='root',
pw='admin')
where dbn -- database you are using (for mysql it is "mysql")
db -- database name
user -- username of your database
pw -- password of your database