Python Mac Os X Mysql Problems

Title: Python Mac OS X MySQL problems Date: 2011-06-21 06:14 Author: eamonnfaherty Category: development Tags: mac os x, mysql, python Slug: python-mac-os-x-mysql-problems

I recently had a three hour head banging off of wall session getting Python to play nicely with MySQL.

I was getting the following error:

File “/Library/Python/2.6/site-packages/Django-1.3-py2.6.egg/django/db/backends/mysql/base.py”, line 14, in raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/eamonnfaherty/.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/eamonnfaherty/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture

This was a complete mix up between 32bit and 64bit Python libraries working together with MySQL.

To fix it I put the following in my .profile file

export PATH=$PATH:/usr/local/mysql/bin

export CC=”gcc-4.0”
export CXX=”g++-4.0”

export PYTHONPATH=”/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/”
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/
export ARCHFLAGS=’-arch i386’
export VERSIONER_PYTHON_PREFER_32_BIT=yes

After adding this I ran a clean, build and install on the mysql-python library and everything worked! Phew!

Published: June 21 2011

  • category:
  • tags:
blog comments powered by Disqus