【问题标题】:gcc-4.2 error when using pip in virtualenv on OSX 10.7在 OSX 10.7 上的 virtualenv 中使用 pip 时出现 gcc-4.2 错误
【发布时间】:2011-12-18 10:33:50
【问题描述】:

我正在尝试在 virtualenv 环境中安装 psycopg2,而且我玩得很开心。我想我可能搞砸了,因为我安装了 virtualenv 然后升级到 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。

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

Cannot install psycopg2 on OSX 10.6.7 with XCode4

GCC error: command 'gcc-4.0' failed with exit status 1

有什么想法吗?您还需要了解哪些其他信息?

【问题讨论】:

    标签: python xcode4 virtualenv pip psycopg2


    【解决方案1】:

    同样的问题。 Lion,最新的 xcode。

    我下载并安装了一个新的 2.7.2 python 和一个 virtualenv。

    $ 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 技巧的需要,因为我是全新安装的。为什么不呢?

    2) 链接器的名称是否有类似的技巧?这可能会深入到 distutils。

    编辑:已解决 遵循许多博客/ SO建议,以下内容对我有用: 回想一下我正在使用运行 python 2.7.2 的 virtualenv 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 应用程序都可以正常工作。符号链接让我可以在我的 virtualenv 中安装也引用 gcc-4.2 的其他包。

    【讨论】:

    • 谢谢!!!你的救命稻草。我尝试了所有方法,最后添加了 ln -s /usr/bin/gcc gcc-4.2 并且成功了!!!
    • 奇怪的是,4 年后在 El Capitan 上仍然解决了我的问题。谢谢!
    【解决方案2】:

    你的错误是这样的:

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

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

    降级(或升级)您的 GCC 版本,或修改软件包以仅使用 gcc 命令构建。

    ln gcc-4.2gcc 命令会更老套。

    【讨论】:

    • 所以,gcc-4.2 似乎已安装。或者至少它存在于 /Developer 目录中。但它肯定不在这个位置:/Developer/SDKs/MacOSX10.6.sdk 这可能是问题的根源吗?
    • 这可能会更清楚地说明这个问题:superuser.com/questions/313107/…
    • 你在链接什么?你想要/usr/bin/gcc-4.2 -> Xcode GCC binary
    • 好的,这意味着gcc-4.2 已经被链接了。 /usr/bin/ 在您的 $PATH 变量中吗?尝试添加它,然后运行编译脚本(在同一个终端窗口中):export PATH=$PATH:/usr/bin/
    • 这样好多了。我环顾四周,您必须进行大量核心编译才能使事情正常进行。如果您想尝试一些东西,请尝试链接一些头文件(那是您的错误)。这个问题正是你的问题:stackoverflow.com/questions/1550397/…
    【解决方案3】:

    我发现在 10.7 上安装 PIL 的最简单方法是创建一个从 gcc-4.2 到 gcc 的符号链接。

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

    【讨论】:

    • 它解决了我的问题。由于我的错误是在 g++-4.2 上,我只是做了“sudo ln -s /usr/bin/gcc /usr/bin/g++-4.2”,一切都很完美。干杯 niallsco!
    【解决方案4】:

    我在 venv w/ 2.7.7 的 OSX Sierra 上安装 mysqlclient 并执行了以下操作:

    xcode-select --install
    export CC=gcc
    export LDSHARED="gcc -Wl,-x -dynamiclib -undefined dynamic_lookup"
    pip install mysqlclient
    

    似乎工作 - gcc-4.2 -bundle 似乎来自 setuptools build_ext 不知何故。

    【讨论】:

    • 谢谢。 export CC=gcc 在类似的情况下为我做了诀窍
    【解决方案5】:

    试试这个

    $ sudo apt-get install python-dev
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-18
      • 1970-01-01
      • 2013-12-02
      • 2015-12-27
      • 2012-08-07
      • 2012-07-27
      • 2015-08-19
      • 1970-01-01
      相关资源
      最近更新 更多