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

10,238

Solution 1

Same problem. Lion, latest xcode.

I downloaded and installed a fresh 2.7.2 python and a single 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. 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. Why not?

2) Is there a similar trick for the name of the linker? This might be getting pretty deep into 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. I upgraded from 8.4 to 9.1. Did not uninstall 8.4, did not lose my databases. 2) added /Library/PostgreSQL/9.1/bin to $PATH. I did this in my .profile because I already had 8.4/bin in there, probably for much the same reason. 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.

However, my django/postgres apps all work. The symlink lets me install other packages that also reference gcc-4.2 in my virtualenv.

Solution 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.

Either downgrade (or upgrade) your GCC version, or modify the package to build with just the gcc command.

A bit more hacky would be to ln gcc-4.2 to the gcc command.

Solution 3

I've found the easiest way to install PIL on 10.7 is to create a symlink from gcc-4.2 to gcc.

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

Solution 4

I was installing mysqlclient on OSX Sierra in venv w/ 2.7.7 and did the following:

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.

Share:
10,238

Related videos on Youtube

TrentonMcManus
Author by

TrentonMcManus

The view is pretty good from over here.

Updated on June 04, 2022

Comments

  • TrentonMcManus
    TrentonMcManus almost 2 years

    I am trying to install psycopg2 in virtualenv enviroment and am having a heck of a time. I think I may have screwed something up because I installed virtualenv and then upgraded to 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.

    I have tried the following solutions, with no success:

    Cannot install psycopg2 on OSX 10.6.7 with XCode4

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

    Any thoughts? What other information would you need to know?

  • TrentonMcManus
    TrentonMcManus over 12 years
    So, gcc-4.2 seems to be installed. Or at least it exists in the /Developer directory. But it is definately not at this location: /Developer/SDKs/MacOSX10.6.sdk Could that be the source of the problem?
  • TrentonMcManus
    TrentonMcManus over 12 years
    This may shed more light on the issue: superuser.com/questions/313107/…
  • Blender
    Blender over 12 years
    Eh, I don't even run Mac, so that would by first stab at it. Did you get the problem solved?
  • TrentonMcManus
    TrentonMcManus over 12 years
    Nope. I tried reinstalling Xcode 4, restarting the computer, and creating symlinks for gcc in the /Developer/SDKs/MacOSX10.6.sdk directory. All to no avail.
  • Blender
    Blender over 12 years
    What are you linking? You want /usr/bin/gcc-4.2 -> Xcode GCC binary.
  • TrentonMcManus
    TrentonMcManus over 12 years
    As far as I know I was linking as you describe. I added /Developers/usr/bin to the $PATH for good measure and still getting the same error. I have given up on trying to fix this, and am going to try re-installing Xcode 3.2.6
  • Blender
    Blender over 12 years
    Can you please run which gcc in Terminal? I'm not sure why this isn't working for you.
  • TrentonMcManus
    TrentonMcManus over 12 years
    Comes back as /Developer/usr/bin/gcc
  • Blender
    Blender over 12 years
    Link it: cd /usr/bin/ && sudo ln -s /Developer/usr/bin/gcc gcc-4.2 and see what happens.
  • TrentonMcManus
    TrentonMcManus over 12 years
    I get this result ln: gcc-4.2: File exists
  • Blender
    Blender over 12 years
    Ok, so that means gcc-4.2 has been linked already. Is /usr/bin/ in your $PATH variable? Try adding it and then run the compile script (while in the same Terminal window): export PATH=$PATH:/usr/bin/
  • TrentonMcManus
    TrentonMcManus over 12 years
    Thank you so much for your help, by the way. I really appreciate it. So here is the update. I have reinstalled OSX. I have installed fresh coppies of Python 2.7.2, easy_install, pip and virtualenv. I have also installed Xcode 4. I tried doing cd /usr/bin/ && sudo ln -s /Developer/usr/bin/gcc gcc-4.2. When I tried that command, no error resulted. When I do which gcc now it returns /usr/bin/gcc. I tried installing psycopg2 again, and ended up with the same error messages: error: command 'gcc-4.2' failed with exit status 1.
  • Blender
    Blender over 12 years
    Could you post the latest error message dump? I think the errors should be different now.
  • Blender
    Blender over 12 years
    That's a lot better. I looked around, and you'll have to do a bunch of hardcore compiling to make things work. If you'd like to try something, try linking a few header files (that was your error). This question is exactly your problem: stackoverflow.com/questions/1550397/…
  • sweyrick
    sweyrick over 11 years
    Thanks!!! Your a life saver. I tried everything and then finally added the ln -s /usr/bin/gcc gcc-4.2 and it worked!!!
  • marcelosalloum
    marcelosalloum over 10 years
    It solved my problem. As my error was on g++-4.2, I just did "sudo ln -s /usr/bin/gcc /usr/bin/g++-4.2" and everything went perfect. Cheers niallsco!
  • jbodily
    jbodily almost 8 years
    Oddly enough, still fixes my problem 4 years later on El Capitan. Thanks!
  • captnswing
    captnswing almost 4 years
    thanks. export CC=gcc did the trick for me in a similar case