无法在带有XCode4的OSX 10.6.7上安装psycopg2
在OSX上安装psycopg2时出现了以下问题:
building 'psycopg2._psycopg' extension
creating build/temp.macosx-10.6-universal-2.6
creating build/temp.macosx-10.6-universal-2.6/psycopg
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 -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090003 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -I. -I/usr/local/Cellar/postgresql/9.0.3/include -I/usr/local/Cellar/postgresql/9.0.3/include/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.6-universal-2.6/psycopg/psycopgmodule.o
/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
psycopg/psycopgmodule.c:1009: fatal error: error writing to -: Broken pipe
compilation terminated.
lipo: can't open input file: /var/folders/zf/zfsYTD29GwSWm+UDcF6VxE+++TM/-Tmp-//ccd8ckcV.out (No such file or directory)
error: command 'gcc-4.2' failed with exit status 1
有没有人知道我该怎么做才能安装成功? 我已经安装了Postgres,而且它似乎运行得很好。
我尝试过用easy_install和pip install,但结果都显示了类似的错误信息。
2 个回答
8
这个问题是因为在OS X 10.6中包含的Python 2.6是为三种架构(i386、x86_64和ppc)构建的,以便与早期版本的OS X兼容。而Python的Distutils工具会确保所有的C扩展模块与Python解释器和库使用相同的arch
架构。但是,Xcode 4似乎不再支持PPC架构。直到有官方的补丁发布,你可以选择以下几种方法:
- 在运行pyscopg2的setup.py脚本时覆盖架构(正如Adam所指出的,Distutils的
ARCHFLAGS
就是这样做的方式) - 回到使用Xcode 3(或者尝试一些不被支持的黑科技,把Xcode 3和Xcode 4一起安装)
- 尝试使用不同版本的Python。例如,python.org提供了一个i386/x86_64版本的Python 2.7的安装程序,可以在这里找到
或者你可以使用第三方包管理器来构建和安装你需要的所有东西,比如MacPorts。
sudo port install py27-psycopg2 # installs Python2.7, portgresql, and pysycopg2
51
看起来ARCHFLAGS这个设置没有生效,所以最后使用了:
sudo env ARCHFLAGS="-arch i386 -arch x86_64" pip install psycopg2
这条命令才成功了。