2011-04-15 129 views
2

我拉着我的头发在这里试图设置我的Mac上MySQLdb为了连接到远程MySQL服务器。麻烦设置MySQLdb模块

  1. 我已经安装了
  2. 我已经安装了XCode 4
  3. 最新的C MySQL客户端库我也天真地尝试安装的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 

我一直在这几天现在它开始我发疯。任何帮助将不胜感激!

+0

WTF与你的CFLAGS? '-arch i386 -arch ppc -arch x86_64'?这是疯狂! – 2011-04-15 03:01:13

+0

这些拱门是OS X 10.6系统Python 2.6的标准版本。 – 2011-04-15 03:12:38

回答

11

您已经通过安装设置自己头痛的新的和前瞻性的Xcode 4,而不是最新版本的Xcode 3这是什么的Mac OS X 10.6与释放。你遇到的直接问题是Python试图用与Python本身相同的配置来构建C扩展模块。对于10.6,包括三种体系结构:i386x86_64ppc(用于与在早期系统上构建的程序的兼容性)。显然Xcode 4已经移除了对建筑ppc拱门的支持。你可能能够通过使用ARCHFLAGS环境变量轻松解决此问题,该变量用于覆盖构建扩展模块时由Python的Distutils使用的拱设置。试着做这样的事情(未经测试,因为我不具备的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这样的软件包管理器安装所有软件,使用完整的解决方案。

+1

工作就像一个魅力,感谢一百万。看起来是时候阅读编译器了... – 2011-04-15 03:17:52

+0

祝你好运!不幸的是,这些东西大部分都很神秘。 – 2011-04-15 03:24:05

+0

谢谢奈德。自从我开始使用OSX进行开发工作以来,这一直是我的一个棘手问题!现在不再需要一个Ubuntu vm了! – ril3y 2011-06-27 13:25:06

2

当我运行命令,构建我接收到错误

python setup.py build 

建筑物_mysql'延伸创建构建/ temp.macosx-10.6-Intel的2.7 铛-fno严格走样-fno- common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -O2 -DNDEBUG -g -O3 -Dversion_info =(1,2,3,'final',0)-D_ 版本 _ = 1.2。 3 -I/Applications/XAMPP/xamppfiles/include/mysql -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.6-intel- 2.7/_mysql.o -mmacosx-version-min = 10.4 -arch i386 -arch ppc -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL clang:警告:未对'powerpc'体系结构使用clang编译器 _mysql.c:36:10:致命错误:'my_config。H”找不到文件

包括‘my_config.h’

0

有,我刚刚找到解决这个另一种方式。 我遇到了和你一样的问题,我的Python版本是2.7.4和Xcode 4.也许你刚刚得到了32位的Python,就像我一样。所以我把它改为2.7.5x64bit,那应该没有问题。