Question

I'm trying to install cython on lion but this is what I get:

$ export CC=gcc-4.2
$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
$ python setup.py install 
error: command 'gcc-4.2' failed with exit status 255

I'm not sure that llvm-gcc is right, I installed Xcode4.1 but it still does no work.

Anyone knows how to fix this?

Was it helpful?

Solution

You need to adjust at least your PATH and LD_LIBRARY_PATH environment variables.

The PATH environment variable also needs to include /Developer/usr/bin. I've written a ~/.bash_devenv file, which I source every time I want to compile C code on my Mac Pro mid-2010 (upgraded from Snow Leopard to Lion to Lion Server).

$ cat ~/.bash_devenv

ARCHFLAGS="-isysroot /Developer/SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7"
LDFLAGS="-L/Developer/SDKs/MacOSX10.7.sdk/usr/lib -L/usr/lib"
CFLAGS="-I/Developer/SDKs/MacOSX10.7.sdk/usr/include -I/usr/include -O2 -pipe -fomit-frame-pointer"
CPPFLAGS="-I/usr/include/ -I/Developer/SDKs/MacOSX10.7.sdk/usr/include"
LD_LIBRARY_PATH="/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/:$LD_LIBRARY_PATH"

case $1 in
    32)
        export LDFLAGS="-arch i386 -arch x86_64 $LDFLAGS"
        export FFLAGS="-m i386 -m x86_64"
        export CFLAGS="-arch i386 -arch x86_64 $CFLAGS"
        export CPPFLAGS="-arch i386 -arch x86_64 $CPPFLAGS"
        export LD_LIBRARY_PATH="/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin11/4.2.1/:$LD_LIBRARY_PATH"
    ;;
    64)
        export LDFLAGS="-arch x86_64 $LDFLAGS"
        export FFLAGS="-m x86_64"
        export CFLAGS="-arch x86_64 $CFLAGS"
        export CPPFLAGS="$CPPFLAGS"
        export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/Developer/SDKs/MacOSX10.7.sdk/usr/lib/gcc/i686-apple-darwin11/4.2.1/"
    ;;
    *)
        export LDFLAGS="$LDFLAGS"
        export FFLAGS="-m x86_64"
        export CFLAGS="-L/Developer/SDKs/MacOSX10.7.sdk/usr/lib -L/usr/lib -arch x86_64 $CFLAGS"
        export CPPFLAGS="$CPPFLAGS"
        export LD_LIBRARY_PATH="/usr/lib:/Developer/SDKs/MacOSX10.7.sdk/usr/lib:$LD_LIBRARY_PATH"
    ;;
esac    

### GLOBALS ###

export PATH="/Developer/usr/bin:/Developer/usr/local/bin:$PATH"


Some of the CFLAGS are probably redundant (the -I/path/to/dir directives), but it should mostly be relevant for any machine running Lion and XCode.

I've just successfully compiled Cython on Lion. It failed though, before I had:
1) Typed the command source ~/.bash_devenv
2) Used a custom version of Python I compiled manually.
  i.e. cython compilation fails with the default install of Python, as it can't find Python.h. If you know where to find the system Python.h and want to use the system Python (not recommended if you want to build your own numpy or other libraries), add the directory containing Python.h to CPPFLAGS; e.g. CPPFLAGS+=" -I/usr/local/include".

Alternatively, download Enthought's Python distribution, which includes cython, as well as lots of other useful libraries, including open source code they've developed internally (cwrap is one module I know of, and is designed to work hand-in-hand with cython).

Safe

OTHER TIPS

sudo CC=llvm-gcc-4.2 python setup.py install

worked fine for me! found it on

http://comments.gmane.org/gmane.comp.python.cython.user/8461

Best!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top