1

I recently upgraded to OSx Mountain Lion (10.8) and shortly after to 10.8.1. I was attempting to do an "import MySQLdb" and ran into the following errors:

>>> import MySQLdb
/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.8-intel.egg/_mysql.py:3: UserWarning: Module _mysql was already imported from /Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.8-intel.egg/_mysql.pyc, but /Users/jlk/Software_Downloads/MySQL-python/MySQL-python-1.2.3 is being added to sys.path
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "MySQLdb/__init__.py", line 19, in <module>
    import _mysql
  File "build/bdist.macosx-10.8-intel/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.8-intel/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/jlk/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.8-intel.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
    /Users/jlk/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.8-intel.egg-tmp/_mysql.so: mach-o, but wrong architecture

Not really sure what is wrong or how to fix it. I have googled around, but am unable to find any answers pertaining to osx 10.8.1 with this issue. It states at the end that its the "wrong architecture", but I know that what I have installed is the OSx version of the module. The only difference I see is that it says its for 10.8, but this is the most current version of the module.

For reference:

OS: OSx Mountain Lion 10.8.1 Pyhon version: 2.7.2

Any ideas?

Regards,

Jeff

numberwhun
  • 956
  • 9
  • 7
  • Ok, I have done more searching and so far, everything that I have found for interacting with MySQL via python seems to want to use the MySQLdb module, which, as stated below, is not currently compatible with the 2.7.x+ version of Python. Does anyone have any ideas as to how else I could interface with mysql using Python, not using that module? – numberwhun Sep 13 '12 at 09:41

1 Answers1

2

It's likely that the python interpreter you're using and the _mysql.so were built for different sets of architectures, e.g. one is i386 only and the other one 32/64 bit fat. You can check that by running file /path/to/your python interpreter and file /path/to_mysql.so and comparing the output.

Can you rebuild MySQLdb and make sure pip / easy_install uses the correct python interpreter? Also, if you haven't done so already, upgrade your Xcode version and its command line tools to avoid the usual spew of build errors.

edit: I could reproduce this on 10.7 with Apple's stock Python 2.7.1. The problem really is an architecture mismatch between the python interpreter, MySQLdb and the MySQL server. Python is a 32/64bit fat build, the MySQL version I have installed is 32bit only. MySQLdb looks at MySQL's architecture when building, so I got a 32bit only _mysql.so. When importing the module in python which probably runs in 64bit mode, the error occurs.

I think installing and running a 64bit version of MySQL and the rebuilding MySQL-Python should solve this, or you could force Python to run in 32bit mode.

Community
  • 1
  • 1
Simon
  • 12,018
  • 4
  • 34
  • 39
  • 1
    I checked the versions as you suggested and they are all correct. After I had upgraded to 10.8 I did re-install xcode and also installed the command line tools. I actually JUST found out via the sourceforge site for this module (http://sourceforge.net/projects/mysql-python/) that it appears Python 2.7 and above versions are coming soon. I am gathering that that may actually be the issue. – numberwhun Sep 09 '12 at 03:42
  • Wow, I can actually reproduce this. I'm on 10.7 with Apple's stock Python 2.7.1 and I'm seeing the same issue. – Simon Sep 10 '12 at 08:39