'Installing PIL on OS X Lion: initialization from incompatible pointer type

I want to run python's ndimage to do some image analysis. I have a 64-bit Mac running OSX Lion and Python 2.7. When I tried to run commands from ndimage commands I found out that I need to install PIL.

I downloaded that and unzipped it (for now into the downloads folder, is there a better place to do it?). I run setup.py and get these messages:

running install
running build
running build_py
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imaging' 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 -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/Library/Frameworks/Python.framework/Versions/2.7/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.6-intel-2.7/_imaging.o
unable to execute gcc-4.2: No such file or directory
error: command 'gcc-4.2' failed with exit status 1

I read Failed to build PIL on Mac OS X 10.7 Lion and made sure that I have the 32/64 bit version of python 2.7 installed (Mac OS X 64-bit/32-bit x86-64/i386 Installer (2.7.2) for Mac OS X 10.6 and 10.7 ). I also have Xcode installed. Am I doing something stupid here?

Edit 1: looking further, I have found this gcc-4.2 failed with exit status 1. I've tried entering this when I get the error:

llvm-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 -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/Library/Frameworks/Python.framework/Versions/2.7/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.6-intel-2.7/_imaging.o

and I get these messages:

_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type
_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type

Edit 2: I'm not sure if this is the right way to go, but I found a post on installing pil on OSX Leopard and, following its advice, got rid of the -arch i386 part of the command and entered:

 llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch x86_64 -g -O2 -DNDEBUG -g -O3 -DHAVE_LIBZ -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -IlibImaging -I/Library/Frameworks/Python.framework/Versions/2.7/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.6-intel-2.7/_imaging.o

Now I only get two errors:

_imaging.c:3017: warning: initialization from incompatible pointer type
_imaging.c:3077: warning: initialization from incompatible pointer type

From what I can tell at this point the program poops out and doesn't finish compiling. Can anyone help me take it from here?



Solution 1:[1]

https://github.com/kennethreitz/osx-gcc-installer/downloads

Download GCC for lion. It solved all the error: command 'gcc-4.2' failed with exit status 1 problems.

Solution 2:[2]

I have had very good success with the MacPorts Python Imaging Library (PIL), Pandas, Numpy and other numerical analysis packages on both Lion and Mountain Lion.

Recently there were some significant upgrades with gcc for integration with the latest numerical Python modules on MacPorts. Looked like a very significant effort. I recommend MacPorts unless you are determined to hash through a native install of PIL on Lion.

Solution 3:[3]

I had compiling problems with PIL with Mountain Lion and python 2.7. I used Pillow instead, it's a friendly PIL fork with wider platform support.

regardins your setup questions:

  • I use macports for python 2.7 and other open source stuff on my mac (libpng, libjpeg, etc for PILLOW)
  • virtualenv for creating a virtual python environment (venv will be built-in into python 3.3)
  • I put source code under ~/src (instead Downloads folder)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ronaldaai
Solution 2 zerocog
Solution 3 yvess