- Download MySQL for Python (the MySQLdb module) source from http://sourceforge.net/projects/mysql-python/ and extract the tar.gz file.
- Open Terminal and navigate to the source folder.
- Type the following to build the module:
python setup.py build
- Then, install the module by typing the following:
sudo python setup.py install
- In a perfect world, this would be all you'd need to do. However, if your computer was like mine, when you try to import the newly-installed module, it'll through the following error:
>>> import MySQLdb Traceback (most recent call last): File "To fix this error, we'll simply make a symlink where libmysqlclient.18.dylib is expected to be to where it really is:
", line 1, in File "MySQLdb/__init__.py", line 19, in import _mysql File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 6, in __bootstrap__ ImportError: dlopen(/Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/username/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so Reason: image not found
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylibNote: you can also fix this issue by changing your path during install as per this suggestion.
Saturday, May 5, 2012
These instructions have been tested on a machine running OS X Lion and Python 2.7.1, but should work for most any Intel setup. Most of the setup is explained in the README file included with the source, and the error at the end was solved per a thread here.