如何在OSX 10.7上安装psycopg2

4 投票
2 回答
4735 浏览
提问于 2025-04-17 08:36

我按照以下步骤操作:

1) $ sudo pip install psycopg2

结果出现了以下错误:

Downloading/unpacking psycopg2
  Running setup.py egg_info for package psycopg2

    no previously-included directories found matching 'doc/src/_build'
Installing collected packages: psycopg2
  Running setup.py install for psycopg2
    building 'psycopg2._psycopg' extension
    llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4.3 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090004 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I. -I/usr/include -I/usr/include/postgresql/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.7-intel-2.7/psycopg/psycopgmodule.o
    unable to execute llvm-gcc-4.2: No such file or directory
    error: command 'llvm-gcc-4.2' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/Users/boltellinfomedia/mukul/mukul/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-8NaS72-record/install-record.txt:
    running install

running build

running build_py

running build_ext

building 'psycopg2._psycopg' extension

llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4.3 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090004 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I. -I/usr/include -I/usr/include/postgresql/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.7-intel-2.7/psycopg/psycopgmodule.o

unable to execute llvm-gcc-4.2: No such file or directory

error: command 'llvm-gcc-4.2' failed with exit status 1

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/Users/boltellinfomedia/mukul/mukul/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-8NaS72-record/install-record.txt failed with error code 1
Storing complete log in /Users/boltellinfomedia/.pip/pip.log

2) 然后我在网上搜索如何安装llvm-gcc-4.2,发现需要安装Xcode,具体信息可以在这个链接找到。

同时,我在这个关于OSX Lion上psycopg2安装问题的帖子中了解到,我可以通过macports来安装psycopg2,但又在这个链接上发现我还是需要安装Xcode。

3) 最后,我尝试从苹果商店安装Xcode,下载了一个1.6GB的文件,之后系统提示我安装完成。下面是安装完成的截图:

![macports安装截图][1]

4) 然后我尝试通过这个链接上的dmg文件来安装macports,但系统提示我Xcode还没有安装。下面是这个提示的截图:![安装macport时,提示Xcode未安装][2]

2 个回答

3

这里还有一个额外的细节。对于Xcode 4.3及更高版本,你需要单独安装命令行工具。这一步是必须的,目的是让脚本能够调用命令行版本的llvm-gcc-4.2。

你可以去Xcode的设置,找到“偏好设置” > “下载” > “安装命令行工具”。

2

问题很可能是你只从App Store下载了Xcode的安装程序。现在你需要运行这个安装程序来安装Xcode。

撰写回答