在OSX 10.7上使用virtualenv时,pip遇到gcc-4.2错误

3 投票
5 回答
10293 浏览
提问于 2025-04-17 05:18

我正在尝试在虚拟环境中安装psycopg2,但遇到了很多麻烦。我觉得我可能搞错了什么,因为我先安装了虚拟环境,然后又升级到了Xcode 4。

(my_enviroment)my_users-macbook-2:my_enviroment my_user$ pip install psycopg2

结果出现了这个信息:

Downloading/unpacking psycopg2==2.4.2
  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
    gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090004 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/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.6-intel-2.7/psycopg/psycopgmodule.o
    unable to execute gcc-4.2: No such file or directory
    error: command 'gcc-4.2' failed with exit status 1
    Complete output from command /Users/my_user/my_enviroment/bin/python -c "import setuptools;__file__='/Users/my_user/my_enviroment/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/b8/jflj9btd4rzb80xfmcy_rk140000gn/T/pip-lojVKc-record/install-record.txt --install-headers /Users/my_user/my_enviroment/bin/../include/site/python2.7:
    running install

running build

running build_py

running build_ext

building 'psycopg2._psycopg' extension

gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -DPSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x090004 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/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.6-intel-2.7/psycopg/psycopgmodule.o

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

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

----------------------------------------
Command /Users/my_user/my_enviroment/bin/python -c "import setuptools;__file__='/Users/my_user/my_enviroment/build/psycopg2/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/b8/jflj9btd4rzb80xfmcy_rk140000gn/T/pip-lojVKc-record/install-record.txt --install-headers /Users/my_user/my_enviroment/bin/../include/site/python2.7 failed with error code 1
Storing complete log in /Users/my_user/.pip/pip.log

我现在使用的是OSX 10.7,Python 2.7.2,pip 1.0.2,Xcode 4。

我尝试了以下几种解决方案,但都没有成功:

无法在OSX 10.6.7上用XCode4安装psycopg2

GCC错误:命令'gcc-4.0'失败,退出状态为1

有什么想法吗?你还需要知道其他什么信息吗?

5 个回答

4

我发现,在10.7系统上安装PIL(Python Imaging Library)最简单的方法是把gcc-4.2这个链接指向gcc。

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
easy_install pil
5

你的错误是这个:

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

这意味着 gcc-4.2 没有安装。

你可以选择降级(或升级)你的GCC版本,或者修改这个包,让它只用 gcc 命令来构建。

还有一种比较“黑科技”的方法,就是把 gcc-4.2 链接到 gcc 命令上。

7

我也遇到了同样的问题。我的系统是Lion,使用的是最新的xcode。

我下载并安装了一个全新的2.7.2版本的Python和一个虚拟环境。

$ which pip
/opt/local/py_env/default/bin/pip
(default)default $ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
(default)default $ which python
/opt/local/py_env/default/bin/python

我添加了:

export CC=/usr/bin/gcc

根据这里很多人提到的关于为什么pip/easy_install等在Lion上有问题的回答,解决了编译的问题,但在链接步骤时还是出现了同样的错误:

    /usr/bin/gcc -fno-strict-aliasing -fno-common -dynamic -isysroot /DeveloperSDKs/MacOSX10.6.sdk -g -O2 -DNDEBUG -g -O3 -arch i386 -arch x86_64 PSYCOPG_DEFAULT_PYDATETIME=1 -DPSYCOPG_VERSION="2.4.2 (dt dec pq3 ext)" -DPG_VERSION_HEX=0x080401 -DPSYCOPG_EXTENSIONS=1 -DPSYCOPG_NEW_BOOLEAN=1 -DHAVE_PQFREEMEM=1 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -I. -I/Library/PostgreSQL/8.4/include -I/Library/PostgreSQL/8.4/include/postgresql/server -c psycopg/typecast.c -o build/temp.macosx-10.6-intel-2.7/psycopg/typecast.o

gcc-4.2 -bundle -undefined dynamic_lookup -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g -arch i386 -arch x86_64 build/temp.macosx-10.6-intel-2.7/psycopg/psycopgmodule.o build/temp.macosx-10.6-intel-2.7/psycopg/green.o build/temp.macosx-10.6-intel-2.7/psycopg/pqpath.o build/temp.macosx-10.6-intel-2.7/psycopg/utils.o build/temp.macosx-10.6-intel-2.7/psycopg/bytes_format.o build/temp.macosx-10.6-intel-2.7/psycopg/connection_int.o build/temp.macosx-10.6-intel-2.7/psycopg/connection_type.o build/temp.macosx-10.6-intel-2.7/psycopg/cursor_int.o build/temp.macosx-10.6-intel-2.7/psycopg/cursor_type.o build/temp.macosx-10.6-intel-2.7/psycopg/lobject_int.o build/temp.macosx-10.6-intel-2.7/psycopg/lobject_type.o build/temp.macosx-10.6-intel-2.7/psycopg/notify_type.o build/temp.macosx-10.6-intel-2.7/psycopg/xid_type.o build/temp.macosx-10.6-intel-2.7/psycopg/adapter_asis.o build/temp.macosx-10.6-intel-2.7/psycopg/adapter_binary.o build/temp.macosx-10.6-intel-2.7/psycopg/adapter_datetime.o build/temp.macosx-10.6-intel-2.7/psycopg/adapter_list.o build/temp.macosx-10.6-intel-2.7/psycopg/adapter_pboolean.o build/temp.macosx-10.6-intel-2.7/psycopg/adapter_pdecimal.o build/temp.macosx-10.6-intel-2.7/psycopg/adapter_pint.o build/temp.macosx-10.6-intel-2.7/psycopg/adapter_pfloat.o build/temp.macosx-10.6-intel-2.7/psycopg/adapter_qstring.o build/temp.macosx-10.6-intel-2.7/psycopg/microprotocols.o build/temp.macosx-10.6-intel-2.7/psycopg/microprotocols_proto.o build/temp.macosx-10.6-intel-2.7/psycopg/typecast.o -L/Library/PostgreSQL/8.4/lib -lpq -lssl -lcrypto -o build/lib.macosx-10.6-intel-2.7/psycopg2/_psycopg.so

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

1) 我以为安装了自己的Python 2.7.2就可以不需要使用CC的技巧,因为我安装的是全新的Python。为什么不呢?

2) 有没有类似的技巧可以用在链接器的名字上?这可能涉及到distutils的更深层次内容。

编辑:已解决 根据很多博客和StackOverflow的建议,以下方法对我有效: 记得我在使用虚拟环境运行Python 2.7.2 0) 在/bin目录下添加了一个符号链接:ln -s /usr/bin/gcc gcc-4.2 1) 安装了最新的Postgres。我从8.4升级到了9.1。没有卸载8.4,也没有丢失我的数据库。 2) 将/Library/PostgreSQL/9.1/bin添加到$PATH。我在我的.profile文件中做了这个,因为我之前已经在里面添加了8.4/bin,可能是出于同样的原因。 3) pip install psycopg2

我仍然不太明白在这种情况下为什么需要符号链接。也许是因为我没有从源代码构建2.7.2。

不过,我的django/postgres应用程序都能正常工作。这个符号链接让我可以在我的虚拟环境中安装其他也引用gcc-4.2的包。

撰写回答