在Mac OS X 10.6 Snow Leopard上使用MAMP安装MySQLdb以供Django使用

4
我知道这不是一个新话题,但似乎没有人能够解决它,至少对于Python 2.6 / Snow Leopard来说是如此。(我找到的Leopard修复程序不适用于Snow Leopard。)
情况是这样的:我正在尝试在我的Mac OS X Snow Leopard笔记本电脑上本地安装Django(10.6.7)。我有Python 2.6.1,这是预装在Snow Leopard中的版本,MySQL-python 1.2.3和MAMP 1.9.6。所有都是最新的版本。
如果我不对MySQLdb软件包进行任何更改,运行python setup.py build会出现数百个或更多错误,其中第一个是:
$ 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'

以及以以下内容结尾:

_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

因此,我更新了site.cfg文件,并将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

仍然是同样的错误。我花了过去两天时间进行故障排除,做了很多其他事情(包括 ez_setup、下载 .egg 文件以及手动更改代码中的一些选项),但是没有任何不同的结果,所以我不会让你感到无聊并透露所有细节。总之,可能有些显而易见的东西我漏掉了,谁知道呢?(希望如此)。Python 和 MySQL 都能正常工作,所以我尚未安装 MySQL 而不是通过 MAMP 进行重新安装,但我一直在尝试避免这样做。但如果有人认为这是必要的,我会尝试的。
非常感谢任何帮助!谢谢。

没有/Applications/MAMP/Library/include目录(显然不存在该目录中的任何文件)。我应该如何知道那里应该有什么文件,以及在哪里可以获取这些文件?谢谢。<br /><br />另外:$ /Applications/MAMP/Library/bin/mysql_config --include -I/Applications/MAMP/Library/include - BBB
MAMP目录中没有mysql.h文件,我在Spotlight中搜索了mysql.h,唯一的结果是正在寻找它并抛出错误的_mysql.c文件。在故障排除中,我认为mysql.h应该是MySQLdb Python包的一部分,但我猜不是 - 它应该是MAMP的一部分?无论哪种方式,我都没有这个名称的文件。运行“/Applications/MAMP/Library/bin/mysql_config --include”会打印“-I/Applications/MAMP/Library/include”。谢谢! - BBB
1个回答

2

我已经按照您的期望使它工作。

有几个问题:

首先,lipo: can't open input file 表示之前编译失败。设置脚本应该真正失败并显示早期错误;我不知道为什么它们没有这样做。

其次,MySQLdb 从 mysql_config 获取所有配置信息。例如,执行 mysql_config --cflags 给出 C 编译器标志。在我的情况下,它发出了 -I/usr/local/Cellar/mysql/5.5.12/include -g。如果其中没有 -arch 标志,则会针对错误的架构。此外,在此安装文件中,链接架构也是从 mysql_config --cflags 派生的,因此链接将针对错误的架构。

使用 ARCHFLAGS 明确设置体系结构就可以解决问题。以下脚本假定您使用的 MySQL 和 Python 构建与由 uname -m 返回的机器体系结构相匹配;如果不是,请明确指定。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接