1

Hi I have the following error when trying to import MySQLdb. Does anyone know what the issue could be?(I'm on a mac)

>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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/christopherfarm/.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/christopherfarm/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture
locoboy
  • 38,002
  • 70
  • 184
  • 260
  • 1
    It said you installed wrong architecture of mysqldb, check your downloaded version against your system's specs? – huy Aug 05 '11 at 09:33
  • 2
    probably a 32/64 bit issue. Could you do "lipo -info /Users/christopherfarm/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so" and edit the output in? – Jacob Aug 05 '11 at 09:34
  • 1
    see http://stackoverflow.com/questions/1448429/how-to-install-mysqldb-python-data-access-library-to-mysql-on-mac-os-x/1448446#1448446 for more on the installation – mmmmmm Aug 05 '11 at 09:35
  • @cularis here's the terminal `ipo -info /Users/christopherfarm/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so Non-fat file: /Users/christopherfarm/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so is architecture: i386 ` – locoboy Aug 05 '11 at 09:38
  • @Mark I tried using macports like you said but am getting the following issue now http://stackoverflow.com/questions/6964292/mysql-python-error-from-macports – locoboy Aug 06 '11 at 02:04

2 Answers2

2

You havbe to either install an egg built for your architecture, or install from source (i.e. .zip or .tar.gz).

pyroscope
  • 4,120
  • 1
  • 18
  • 13
  • sorry I'm new to all this, how do I know what architecture I need and how do I make sure that I get the right one? – locoboy Aug 05 '11 at 09:44
  • The "install from source" is covered in the answer that Mark linked. Cudos to him. – pyroscope Aug 05 '11 at 09:59
  • I tried using what Mark said but get the following problem http://stackoverflow.com/questions/6964292/mysql-python-error-from-macports – locoboy Aug 06 '11 at 02:04
1

Me too I had a lot of headache with MySQLdb.

If you are starting new development I would suggest to switch to the official MysQL Python Connector: (available on PyPI):

sudo pip install mysql-connector-python

or by download from: http://dev.mysql.com/downloads/connector/python/

Documentation: http://dev.mysql.com/doc/refman/5.5/en/connector-python.html

It's easy to use and also compatible with PEP 249 (Python DB API version 2.0).