Install MySQLdb for Django on Mac OS X 10.6 Snow Leopard with MAMP

So, I know that this is not a new topic, but it that no one seems to be able to solve, at least not for Python 2.6 / Snow Leopard. (The Leopard fixes I found are not applicable to Snow Leopard.)

Situation: I am trying to install Django locally on my Mac OS X Snow Leopard laptop. (10.6.7) I have Python 2.6.1 that was preinstalled using Snow Leopard, MySQL-python 1.2.3, and MAMP 1.9.6. All latest versions of latest versions.

Without making any changes to the MySQLdb package, if I run python setup.py build , I get hundreds or more errors, the first of which:

 $ python setup.py build running build running build_py copying MySQLdb/release.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb running build_ext building '_mysql' extension creating build/temp.macosx-10.6-universal-2.6 gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/Applications/MAMP/Library/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-universal-2.6/_mysql.o -fno-omit-frame-pointer -g _mysql.c:36:23: error: my_config.h: No such file or directory _mysql.c:38:19: error: mysql.h: No such file or directory _mysql.c:39:26: error: mysqld_error.h: No such file or directory _mysql.c:40:20: error: errmsg.h: No such file or directory _mysql.c:76: error: expected specifier-qualifier-list before 'MYSQL' _mysql.c:90: error: expected specifier-qualifier-list before 'MYSQL_RES' 

and ending with:

 _mysql.c:2422: error: initializer element is not constant _mysql.c:2422: error: (near initialization for '_mysql_ResultObject_memberlist[0].offset') _mysql.c: In function '_mysql_ConnectionObject_getattr': _mysql.c:2444: error: '_mysql_ConnectionObject' has no member named 'open' lipo: can't open input file: /var/folders/Br/Br8Yhf-IGVCaGfXw4TYRc++++TI/-Tmp-//ccFnIslh.out (No such file or directory) error: command 'gcc-4.2' failed with exit status 1 

So, I updated my site.cfg file with the mysql_config location:

 # The path to mysql_config. # Only use this if mysql_config is not on your PATH, or you have some weird # setup that requires it. mysql_config = /Applications/MAMP/Library/bin/mysql_config 

Still the same error. I spent the last two days troubleshooting, so I did a whole bunch of other things (including ez_setup , downloading .egg files and manually changing some parameters in the code), but none of them gave any different results, so I won’t bother you all the details. In general, maybe something obvious, I went missing, who knows? (with hope). Python and MySQL work fine, so one thing that I haven't done yet and tried to avoid is reinstalling MySQL not through MAMP. But if anyone has reason to believe that this is necessary, I will try.

Any help would be greatly appreciated! Thanks.

+4
source share
1 answer

I was able to get this job the way you expected.

A few things:

First of all, lipo: can't open input file indicates a previous compilation failure. Installation scripts should be really unsuccessful and show an earlier error; I do not know why this is not so.

Secondly, MySQLdb gets all its configuration information from mysql_config . So, for example, executing mysql_config --cflags gives C compiler flags. In my case, it emitted -I/usr/local/Cellar/mysql/5.5.12/include -g . In the absence of the -arch flag there, the wrong architecture becomes targeted. In addition, the architecture binding (in this installation file) also comes from mysql_config --cflags , so the binding will target the wrong architecture.

Configuring the architecture explicitly with ARCHFLAGS does the trick. The following script assumes that MySQL and python are building what you use matches your machine architecture returned by uname -m ; if not, indicate it explicitly.

 [user]$ sudo su [root]$ export ARCHFLAGS="-arch $(uname -m)" # or '-arch i386' or '-arch x86_64' [root]$ pip install mysql-python 
+2
source

All Articles