Robin Robin - 4 years ago 190
SQL Question connect to mysql error

when i use to connect local mysql, some error show:

Traceback (most recent call last):
File "", line 7, in <module>
db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
File "/Library/Python/2.6/site-packages/", line 1078, in database
return _databases[dbn](**params)
File "/Library/Python/2.6/site-packages/", line 928, in __init__
import MySQLdb as db
File "build/bdist.macosx-10.6-universal/egg/MySQLdb/", line 19, in <module>
File "build/bdist.macosx-10.6-universal/egg/", line 7, in <module>
File "build/bdist.macosx-10.6-universal/egg/", line 6, in __bootstrap__
ImportError: dlopen(/Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/, 2): no suitable image found. Did find:
/Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/ mach-o, but wrong architecture

my python code like this:

import web
render = web.template.render('templates/')
urls = (
app = web.application(urls,globals())
db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
class index:
def GET(self):
todos ='todo')
return render.index(todos)
if __name__=="__main__"

my python version is 2.6.1

how could i fix it ?


Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download