在Mac OS X 10.6 Snow Leopard与MAMP上安装用于Django的MySQLdb [英] Installing MySQLdb for Django on Mac OS X 10.6 Snow Leopard with MAMP

查看:175
本文介绍了在Mac OS X 10.6 Snow Leopard与MAMP上安装用于Django的MySQLdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道这不是一个新的话题,但是没有人似乎能够解决这个问题,至少不适用于Python 2.6 / Snow Leopard。 (我发现的豹修复不适用于雪豹。)



情况:我试图让Django在本地安装在我的Mac OS X雪豹笔记本电脑。 (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 
运行构建
运行build_py
复制MySQLdb / release.py - > build / lib.macosx-10.6-universal-2.6 / MySQLdb
运行build_ext
构建'_mysql'扩展名
创建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:没有这样的文件或目录
_mysql.c:38:19:错误:mysql.h:没有这样的文件或目录
_mysql.c:39:26:错误:mysqld_error.h:没有这样的文件或目录
_mysql .c:40:20:错误:errmsg.h:没有这样的文件或目录
_mysql.c:76:错误:'MYSQL'之前的specifier-qualifier-list
_mysql.c:90: error:在'MYSQL_RES'$之前的期望的specifier-qualifier-list b $ b

,结尾为:

  _mysql.c:2422:error:initializer元素不是常量
_mysql.c:2422:错误:(初始化为'_mysql_ResultObject_memberlist [0] .offset')
_mysql。 c:在函数'_mysql_ConnectionObject_getattr'中:
_mysql.c:2444:错误:'_mysql_ConnectionObject'没有名为'open'的成员
lipo:无法打开输入文件:/ var / folders / Br / Br8Yhf-IGVCaGfXw4TYRc ++++ TI / -Tmp - // ccFnIslh.out(没有这样的文件或目录)
错误:命令'gcc-4.2'失败,退出状态1

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

 #mysql_config的路径。 
#只有当mysql_config不在你的PATH上,或者你有一些奇怪的
#安装程序需要它时才使用这个。
mysql_config = / Applications / MAMP / Library / bin / mysql_config

仍然是一样的错误。我花了两天的时间进行故障诊断,所以我已经做了很多其他的事情(包括 ez_setup ,下载.egg文件,并手动更改一些选项代码),但都没有产生任何不同的结果,所以我不会告诉你所有的细节。一般来说,可能有一些明显的事情我失踪了,谁知道? (希望)。 Python和MySQL都工作正常,所以我没有做的一件事是试图避免的是重新安装MySQL,而不是通过MAMP。但是如果有人有理由相信这是必要的,我会尝试一下。



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

解决方案

我能够按照你的预期得到这个工作。



几件事:



首先, lipo:无法打开输入文件表示先前的编译失败。安装脚本实际上应该是失败并显示较早的错误;我不知道为什么他们不是。



其次,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)#或'-arch i386'或'-arch x86_64'
[root] $ pip install mysql-python


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.

解决方案

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

这篇关于在Mac OS X 10.6 Snow Leopard与MAMP上安装用于Django的MySQLdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆