django - 使用 MAMP 在 Mac OS X 10.6 Snow Leopard 上安装 MySQLdb for Django

标签 django macos installation python-2.6 mysql-python

所以我知道这不是一个新主题,但似乎没有人能够解决这个问题,至少对于 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

所以我用 mysql_config 的位置更新了我的 site.cfg 文件:

# 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 都工作得很好,所以我没有做并且试图避免的一件事是不通过 MAMP 重新安装 MySQL。但如果有人有理由相信这是必要的,我会尝试一下。

任何帮助将不胜感激!谢谢。

最佳答案

我能够按照您的预期使其正常工作。

有几件事:

首先,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

关于django - 使用 MAMP 在 Mac OS X 10.6 Snow Leopard 上安装 MySQLdb for Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6235408/

相关文章:

linux - 运行 shell 脚本以在日志中附加日期的基本 Cron 作业,不起作用

docker - 如何将CouchDB服务器添加到Docker创建文件中

python - Django 模板和应用程序未加载

django - Zappa/AWS - 电子邮件不会发送,只是超时

python - 编写验证码装饰器时出现属性错误

windows - 如何在 Delphi XE5 上安装 Cindy Component?

ruby-on-rails - 无法构建 gem native 扩展。 + rake 失败,退出代码 1

django admin 上传文件处理

macos - Gatekeeper 拒绝我的应用程序包

python - 为什么 QFontDialog.getFont() 总是返回相同的字体?