I’ve just finished trying to install mysql-python on OSX Leopard, and had quite a few problems. This is the procedure that finally ended up working for me.
First, download mysql-python from here.
Unzip and try to build it :
> tar xvzf MySQL-python-1.2.3c1.tar.gz
> cd MySQL-python-1.2.3c1
> sudo python setup.py build
If the build works, you’re in luck… you simply need to install it :
> sudo python setup.py install
More than likely though, it isn’t going to work :) At first, i got an error about LONG_BIT definition appears wrong for platform (bad gcc/glibc config?) :
running buildrunning build_py
copying MySQLdb/release.py -> build/lib.macosx-10.5-i386-2.5/MySQLdb
building '_mysql' extension
/usr/bin/gcc-4.0 -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,3,'gamma',1) -D__version__=1.2.3c1 -I/usr/local/mysql-5.1.30-osx10.5-x86_64/include -I/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5 -c _mysql.c -o build/temp.macosx-10.5-i386-2.5/_mysql.o -g -Os -arch x86_64 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL
In file included from /opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:57,
/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyport.h:761:2: error: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."In file included from _mysql.c:36:
/usr/local/mysql-5.1.30-osx10.5-x86_64/include/my_config.h:1104:1: warning: "SIZEOF_LONG" redefined
In file included from /opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/Python.h:8,
/opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyconfig.h:814:1: warning: this is the location of the previous definition
error: command'/usr/bin/gcc-4.0' failed with exit status 1
To get around this, edit the file mentioned in the error ( /opt/local/Library/Frameworks/Python.framework/Versions/2.5/include/python2.5/pyport.h) and comment out the line mentioned in the error (line 761 in the current version) :
/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent * 32-bit platforms using gcc. We try to catch that here at compile-time * rather than waiting for integer multiplication to trigger bogus * overflows. *//*#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."*/
At this point, hopefully you can build and install without problems :
Even after i managed to install it, i continued to get the following error :
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dynamic module does not define init function(init_mysql)
After a bit of digging around, it turns out that this is caused by running a 32-bit version of python alongside a 64-bit version of MySQL.
We need to uninstall the 64-bit version first. I found some great instructions on akrabat.com :
To uninstall MySQL and completely remove it from you Mac do the following:
* sudo rm /usr/local/mysql
* sudo rm -rf /usr/local/mysql*
* sudo rm -rf /Library/StartupItems/MySQLCOM
* sudo rm -rf /Library/PreferencePanes/My*
* edit /etc/hostconfig and remove the line MYSQLCOM=-YES-
* sudo rm -rf /Library/Receipts/mysql*
* sudo rm -rf /Library/Receipts/MySQL*
The last two lines are particularly important as otherwise, you can't install an older version of MySQL even though you think that you've completely deleted the newer version!
Once this is done, download and install the Mac OS X 10.5 (x86) version from the mysql site (make sure you don’t get the x86_64 version again!), and with a bit of luck everything should be working.