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

♀尐吖头ヾ 提交于 2020-01-13 03:49:28

问题


So I know this is not a new topic, but its one that nobody has seemed to be able to solve, at least not for Python 2.6 / Snow Leopard. (The Leopard fixes I've found aren't applicable to Snow Leopard.)

Situation: I'm trying to get Django installed locally on my Mac OS X Snow Leopard laptop. (10.6.7) I have Python 2.6.1, which is what came preinstalled with Snow Leopard, MySQL-python 1.2.3, and MAMP 1.9.6. All are latest current 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 are:

$ 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 location of mysql_config:

# 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've spent the past two days troubleshooting, so I've done a whole bunch of other things (including the ez_setup, downloading .egg files, and manually changing some options in the code), but none of them have yielded any different results, so I won't bore you with all of the details. In general, there could be something obvious I'm missing, who knows? (hopefully). Python and MySQL both work fine, so one thing I have not done and was trying to avoid is a reinstall of MySQL not through MAMP. But if anybody has reason to believe that's necessary, I'll try it.

Any help would be much appreciated! Thanks.


回答1:


I was able to get this working as you'd expect.

A couple things:

First of all, the lipo: can't open input file indicates a prior compile failure. The setup scripts should really be failing and showing an earlier error; I don't know why they aren't.

Secondly, MySQLdb gets all its config information from mysql_config. So for instance, executing mysql_config --cflags gives the C compiler flags. In my case it emitted -I/usr/local/Cellar/mysql/5.5.12/include -g. In the absence of a -arch flag in there, the wrong architecture gets targeted. Also, linking architecture (in this setup file) is derived from mysql_config --cflags as well, so linking will target the wrong architecture.

Setting the architecture explicitly using ARCHFLAGS does the trick. The following script assumes that the MySQL and python builds that you are using match your machine architecture as returned by uname -m; if not, specify it explicitly.

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


来源:https://stackoverflow.com/questions/6235408/installing-mysqldb-for-django-on-mac-os-x-10-6-snow-leopard-with-mamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!