简体   繁体   English

在OSX 10.7上使用virtualenv中的pip时出现gcc-4.2错误

[英]gcc-4.2 error when using pip in virtualenv on OSX 10.7

I am trying to install psycopg2 in virtualenv enviroment and am having a heck of a time. 我正在尝试在virtualenv环境中安装psycopg2并且有一点时间。 I think I may have screwed something up because I installed virtualenv and then upgraded to Xcode 4. 我想我可能已经搞砸了,因为我安装了virtualenv,然后升级到Xcode 4。

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

Produces this message: 生成此消息:

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

I am running OSX 10.7, Python 2.7.2, pip 1.0.2, Xcode 4. 我正在运行OSX 10.7,Python 2.7.2,pip 1.0.2,Xcode 4。

I have tried the following solutions, with no success: 我尝试了以下解决方案,但没有成功:

Cannot install psycopg2 on OSX 10.6.7 with XCode4 无法使用XCode4在OSX 10.6.7上安装psycopg2

GCC error: command 'gcc-4.0' failed with exit status 1 GCC错误:命令'gcc-4.0'失败,退出状态为1

Any thoughts? 有什么想法吗? What other information would you need to know? 您需要了解哪些其他信息?

Same problem. 同样的问题。 Lion, latest xcode. 狮子,最新的xcode。

I downloaded and installed a fresh 2.7.2 python and a single virtualenv. 我下载并安装了一个新的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

I added: 我补充说:

export CC=/usr/bin/gcc

based on the many answers here about why pip/easy_install, etc. are having trouble with Lion. 基于这里的许多答案,为什么pip / easy_install等与Lion有问题。 That solved the compiling issue, but it fails with the same error on the link step: 这解决了编译问题,但它在链接步骤中失败并出现相同的错误:

    /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) I thought that by installing my own Python 2.7.2 that I'd get around the need to use the CC trick because I installed my python fresh. 1)我认为通过安装我自己的Python 2.7.2,我可以解决使用CC技巧的需要,因为我安装了我的python。 Why not? 为什么不?

2) Is there a similar trick for the name of the linker? 2)链接器的名称是否有类似的技巧? This might be getting pretty deep into distutils. 这可能会深入到distutils。

EDIT: RESOLVED Following many blog/SO suggestions the following worked for me: Recall I am using virtualenv running python 2.7.2 0) added symlink to /bin: ln -s /usr/bin/gcc gcc-4.2 1) Installed latest Postgres. 编辑:已解决以下许多博客/ SO建议以下为我工作:回想一下我使用virtualenv运行python 2.7.2 0)添加符号链接到/ bin:ln -s / usr / bin / gcc gcc-4.2 1)安装最新Postgres 。 I upgraded from 8.4 to 9.1. 我从8.4升级到9.1。 Did not uninstall 8.4, did not lose my databases. 没有卸载8.4,没有丢失我的数据库。 2) added /Library/PostgreSQL/9.1/bin to $PATH. 2)将/Library/PostgreSQL/9.1/bin添加到$ PATH。 I did this in my .profile because I already had 8.4/bin in there, probably for much the same reason. 我在我的.profile中做了这个,因为我已经有8.4 / bin,可能出于同样的原因。 3) pip install psycopg2 3)pip install psycopg2

I still am not sure why I need the symlink in this situation. 我仍然不确定为什么在这种情况下我需要符号链接。 Perhaps because I did not build 2.7.2 from source. 也许是因为我没有从源代码构建2.7.2。

However, my django/postgres apps all work. 但是,我的django / postgres应用程序都可以正常工作。 The symlink lets me install other packages that also reference gcc-4.2 in my virtualenv. 符号链接允许我安装其他包也引用我的virtualenv中的gcc-4.2。

Your error is this: 你的错误是这样的:

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

Which means that gcc-4.2 is not installed. 这意味着没有安装gcc-4.2

Either downgrade (or upgrade) your GCC version, or modify the package to build with just the gcc command. 要么降级(或升级)您的GCC版本,要么仅使用gcc命令修改要构建的包。

A bit more hacky would be to ln gcc-4.2 to the gcc command. 多一点哈克将ln gcc-4.2gcc命令。

I've found the easiest way to install PIL on 10.7 is to create a symlink from gcc-4.2 to gcc. 我发现在10.7上安装PIL的最简单方法是创建一个从gcc-4.2到gcc的符号链接。

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

I was installing mysqlclient on OSX Sierra in venv w/ 2.7.7 and did the following: 我正在使用2.7.7版本的OSV Sierra上安装mysqlclient并执行以下操作:

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

Seemed to work - the gcc-4.2 -bundle appears to come from setuptools build_ext somehow. 似乎工作 - gcc-4.2 -bundle似乎来自setuptools build_ext。

尝试这个

$ sudo apt-get install python-dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM