【问题标题】:Trouble Setting Up MySQLdb Module设置 MySQLdb 模块时遇到问题
【发布时间】:2011-08-06 00:02:36
【问题描述】:

为了连接到远程 MySQL 服务器,我正试图在我的 Mac 上设置 MySQLdb。

  1. 我已经安装了最新的 C MySQL 客户端库
  2. 我已经安装了 XCode 4
  3. 在安装 XCode 或客户端库之前,我曾天真地尝试安装模块

我正在尝试通过在终端中运行以下命令来设置模块:

$ sudo python setup.py build

$ sudo python setup.py install

这两个命令都失败并显示类似的错误消息。这是第一个堆栈跟踪:

running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
running build_ext
building '_mysql' extension
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/usr/include/mysql -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 -pipe
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1030:2: warning: #warning defining SIZEOF_CHARP = 4
/usr/include/mysql/my_config.h:1044:2: warning: #warning defining SIZEOF_LONG = 4
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1030:2: warning: #warning defining SIZEOF_CHARP = 4
/usr/include/mysql/my_config.h:1044:2: warning: #warning defining SIZEOF_LONG = 4
/usr/include/mysql/my_config.h:1151:1: warning: "WORDS_BIGENDIAN" redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:1014:1: warning: this is the location of the previous definition
_mysql.c:2888: fatal error: error writing to -: Broken pipe
compilation terminated.
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1027:2: warning: #warning defining SIZEOF_CHARP = 8
/usr/include/mysql/my_config.h:1041:2: warning: #warning defining SIZEOF_LONG = 8
lipo: can't open input file: /var/tmp//ccU6bipK.out (No such file or directory)
error: command 'gcc-4.2' failed with exit status 1

这是第二个命令的堆栈跟踪:

running install
running bdist_egg
running egg_info
writing MySQL_python.egg-info/PKG-INFO
writing top-level names to MySQL_python.egg-info/top_level.txt
writing dependency_links to MySQL_python.egg-info/dependency_links.txt
reading manifest file 'MySQL_python.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
writing manifest file 'MySQL_python.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-10.6-universal/egg
running install_lib
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.6-universal-2.6/MySQLdb
running build_ext
building '_mysql' extension
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/usr/include/mysql -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 -pipe
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1030:2: warning: #warning defining SIZEOF_CHARP = 4
/usr/include/mysql/my_config.h:1044:2: warning: #warning defining SIZEOF_LONG = 4
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler (/usr/bin/../libexec/gcc/darwin/ppc/as or /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1030:2: warning: #warning defining SIZEOF_CHARP = 4
/usr/include/mysql/my_config.h:1044:2: warning: #warning defining SIZEOF_LONG = 4
/usr/include/mysql/my_config.h:1151:1: warning: "WORDS_BIGENDIAN" redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:8,
                 from pymemcompat.h:10,
                 from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h:1014:1: warning: this is the location of the previous definition
_mysql.c:2888: fatal error: error writing to -: Broken pipe
compilation terminated.
In file included from _mysql.c:36:
/usr/include/mysql/my_config.h:1027:2: warning: #warning defining SIZEOF_CHARP = 8
/usr/include/mysql/my_config.h:1041:2: warning: #warning defining SIZEOF_LONG = 8
lipo: can't open input file: /var/tmp//cchhckGP.out (No such file or directory)
error: command 'gcc-4.2' failed with exit status 1

我已经在这玩了几天了,它开始让我发疯了。任何帮助将不胜感激!

【问题讨论】:

  • WTF 更新了你的 CFLAGS 吗? -arch i386 -arch ppc -arch x86_64?这太疯狂了!
  • 这些拱门是 OS X 10.6 中系统 Python 2.6 的标准配置。

标签: python mysql macos python-module mysql-python


【解决方案1】:

安装新的具有前瞻性的Xcode 4 而不是Mac OS X 10.6 发布时附带的最新版本Xcode 3,让您头疼不已。您遇到的直接问题是 Python 尝试使用与 Python 本身构建的相同配置构建 C 扩展模块。对于 10.6,它包括三种架构:i386x86_64ppc(为了与早期系统上构建的程序兼容)。显然Xcode 4 已经取消了对构建ppc 拱门的支持。您也许可以通过使用ARCHFLAGS 环境变量轻松解决此问题,该环境变量用于覆盖Python 的Distutils 在构建扩展模块时使用的arch 设置。尝试做这样的事情(未经测试,因为我手边没有 Xcode 4):

sudo bash
export ARCHFLAGS='-arch i386 -arch x86_64'
rm -r build
python setup.py build
python setup.py install

按照其他地方的建议,更好的解决方案是不要尝试使用系统 Python 和 MySQL 二进制安装程序在 10.6 上安装 MySQLdb。相反,通过 MacPorts 之类的包管理器安装所有内容,从而使用完整的解决方案。

【讨论】:

  • 工作就像一个魅力,感谢一百万。看起来是时候阅读编译器了...
  • 祝你好运!不幸的是,大部分这些东西都非常神秘。
  • 谢谢内德。自从我切换到 OSX 进行开发工作以来,这一直是我的眼中钉!现在不再需要 ubuntu 虚拟机了!
【解决方案2】:

我刚刚找到了另一种解决此问题的方法。 我遇到了和你一样的问题,我的python版本是2.7.4,Xcode 4。也许你和我一样刚拿到32位的python。于是我把它改成了2.7.5x64bit,那么应该没有问题了。

【讨论】:

    猜你喜欢
    • 2017-07-07
    • 2011-11-28
    • 1970-01-01
    • 2012-01-07
    • 2019-11-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多