无法在带有XCode4的OSX 10.6.7上安装psycopg2

19
在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个回答

51

看起来 ARCHFLAGS 没有生效,最终使用以下命令成功安装 psycopg2:

sudo env ARCHFLAGS="-arch i386 -arch x86_64" pip install psycopg2


遇到了同样的问题,这个方法确实有效!请将其标记为答案。 - Bach

8

问题在于OS X 10.6自带的Python 2.6是为三种支持体系架构(i386,x86_64和ppc为了兼容早期版本的OS X)而构建的。而Python的Distutils尝试确保所有C扩展模块都与Python解释器和库使用相同的arch。但是,Xcode 4显然删除了对PPC的支持。在官方补丁到来之前,你可以选择以下任一方法:

  • override the archs when running the setup.py script for pyscopg2 (as Adam points out, the Distutils ARCHFLAGS is the way to do that)
  • go back to using Xcode 3 (or try some unsupported hacks for installing Xcode 3 along side of Xcode 4)
  • try using a different Python. For instance, for Python 2.7, python.org provides an installer for an i386/x86_64 Python here
  • or you could build and install everything you need using a third-party package manager, like MacPorts.

    sudo port install py27-psycopg2 # installs Python2.7, portgresql, and pysycopg2
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接