简体   繁体   English

设置MySQLdb模块时遇到问题

[英]Trouble Setting Up MySQLdb Module

I'm pulling my hair out over here trying to set up MySQLdb on my Mac in order to connect to a remote MySQL server. 为了连接到远程MySQL服务器,我试着在我的Mac上设置MySQLdb,然后把头发拉到这里。

  1. I have installed the latest C MySQL client libraries 我已经安装了最新的C MySQL客户端库
  2. I have installed XCode 4 我安装了XCode 4
  3. I did naively try to install the module before installing XCode or the client libraries 在安装XCode或客户端库之前,我天真地尝试安装模块

I am attempting to set up the module by running the following commands in terminal: 我试图通过在终端中运行以下命令来设置模块:

$ sudo python setup.py build $ sudo python setup.py build

$ sudo python setup.py install $ sudo python setup.py install

Both of these commands fail with similar error messages. 这两个命令都失败并出现类似的错误消息。 Here is the first stack trace: 这是第一个堆栈跟踪:

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

And here is the stack trace for the second command: 这是第二个命令的堆栈跟踪:

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

I have been at this for a few days now and it's starting to drive me nuts. 我已经在这几天了,它开始让我疯狂。 Any help would be greatly appreciated! 任何帮助将不胜感激!

You've set yourself up for headaches by installing the new and forward-looking Xcode 4 rather than the latest version of Xcode 3 which is what Mac OS X 10.6 was released with. 通过安装新的和前瞻性的Xcode 4而不是Mac OS X 10.6发布的最新版本的Xcode 3 ,你已经让自己陷入了麻烦。 The immediate issue you are running into is that Python tries to build C extension modules with the same configuration that Python itself was built. 您遇到的直接问题是Python尝试使用与Python本身构建相同的配置来构建C扩展模块。 For 10.6, that includes three architectures: i386 , x86_64 , and ppc (for compatibility with programs build on earlier systems). 对于10.6,它包括三种体系结构: i386x86_64ppc (用于与早期系统上构建的程序兼容)。 Apparently Xcode 4 has removed support for building ppc archs. 显然Xcode 4已经取消了对构建ppc拱门的支持。 You may be able to get around this issue easily by using the ARCHFLAGS environment variable which is used to override the arch settings used by Python's Distutils when building extension modules. 可以使用ARCHFLAGS环境变量轻松解决此问题,该变量用于在构建扩展模块时覆盖Python的Distutils使用的arch设置。 Try doing something like this (untested as I don't have Xcode 4 handy): 尝试做这样的事情(未经测试,因为我没有Xcode 4方便):

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

A better solution, as recommended elsewhere, is to not try to install MySQLdb on 10.6 by using the system Python and the MySQL binary installers. 如其他地方所推荐的,更好的解决方案是不要尝试使用系统Python和MySQL二进制安装程序在10.6上安装MySQLdb。 Rather, use a complete solution by installing everything via a package manager like MacPorts. 相反,通过像MacPorts这样的包管理器安装所有内容来使用完整的解决方案。

There is another way that I just found to solve this. 我刚刚发现了另一种方法来解决这个问题。 I encountered the same problem as you did, and my python's version is 2.7.4, and Xcode 4. Maybe you have just got the python of 32 bits, as I did. 我遇到了和你一样的问题,我的python的版本是2.7.4和Xcode 4.也许你刚刚得到了32位的python,就像我做的那样。 So I changed it to 2.7.5x64bit , then there should be no problems. 所以我将其改为2.7.5x64bit ,那么应该没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM