0

When I install PIL (or pillow), the _imaging C module does not install.

This is a common error, and have seen ApPeL's play-by-play solution that most have found helpful. Unfortunately, when I run sudo python setup.py install, I get the following error:

running install
running build
running build_py
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imaging' extension
gcc-4.0 -fno-strict-aliasing -fno-common -dynamic -arch ppc -arch i386 -g -O2 -DNDEBUG -g -O3 -DHAVE_LIBJPEG -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/local/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.3-fat-2.7/_imaging.o
unable to execute gcc-4.0: No such file or directory
error: command 'gcc-4.0' failed with exit status 1

When I run python in the shell, and try to import the modules, I get these import errors:

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:32:06) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> import Image
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Image
>>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named _imaging

I've had similar errors previously, and Ned Deily has been kind enough to provide solutions. I believe my current problem may be linked to this previous question:

OSX: error when installing Python packages (including this as reference)

Here's some other potentially useful information:

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:32:06) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ gcc
i686-apple-darwin11-llvm-gcc-4.2: no input files

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

Santiagos-MacBook-Air:Imaging-1.1.7 sgarza621$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

I'm not very familiar with the ins and outs if gcc, Xcode, or PIL. So, if you don't mind, please provide detailed responses so that I understand how to act on your solution. Also, let me know if I can provide more details, and I will edit them into the question.


EDIT:

I've installed pillow with pip, as suggested by MattDMo, Image now imports successfully, but _imaging does not (I believe the c extensions aren't being properly compiled by gcc on my machine, see above):

Santiagos-MacBook-Air:riotry_mobile sgarza621$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:32:06) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Image
>>> import _imaging
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_imaging.so
  Expected in: dynamic lookup

I'm using PIL to process images on a Django web app, and I get the following error when I try to upload an image through a form for processing by PIL:

The _imaging C module is not installed

SECOND EDIT:

Here's more information, related to the python and gcc, which I hope will shed light on the problem:

$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ /usr/bin/python -c 'import sys;print(sys.version)'
2.7.2 (default, Jun 16 2012, 12:38:40) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
$ /usr/bin/python2.7 -c 'import sys;print(sys.version)'
2.7.2 (default, Jun 16 2012, 12:38:40) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)]
Community
  • 1
  • 1
sgarza62
  • 5,998
  • 8
  • 49
  • 69

2 Answers2

2

Many if not all of your problems (hopefully) can be solved by using Pillow instead. PIL development was just kind of halted a while back, and unfortunately the code wasn't forwards-compatible in any way, so as compilers and Python matured, errors crept in. The Pillow fork is stable, actively developed, and pretty widespread, so you can feel safe using it. Version 2.0 has a bunch of enhancements, including Python 3 support. You'll have to use from PIL import Image instead of import Image, though. Good luck!

MattDMo
  • 100,794
  • 21
  • 241
  • 231
0

Wow. I hope this helps people who have the same problem in the future, because that was brutal.

The solution was to install the python.org 64-bit/32-bit installer for Mac, as outlined in Ned Deily's answer to the question “…can't figure out the architecture type of…” problem when compiling Python C-extension with gcc.

First, I made sure that the default python was this new python (just by running python in the shell).

Then, I reinstalled pip, and ran pip install PIL. And that did it!

Just to make sure, I opened up python in the shell, and imported the three modules:

>>> import PIL
>>> import Image
>>> import _imaging

All of them (finally) imported without errors.

Community
  • 1
  • 1
sgarza62
  • 5,998
  • 8
  • 49
  • 69
  • 1
    Glad you got things to work. There are other possible pitfalls with install PIL on OS X. OS X does not ship with the libraries PIL needs for JPEG support; if you need that, you may need to also build and install libjpeg and rebuild PIL. It appears that your original problems were caused by using the python.org OS X 32-bit-only installer for Python 2.7.3 with Xcode 4 (on OS X 10.7 or 10.8). That combination does not work well without tweaking. Using the 64-bit/32-bit installer for 2.7.3 as you found works better. (2.7.4 which will be released shortly works better). – Ned Deily Apr 04 '13 at 03:52
  • 1
    But, because PIL requires additional third-party libraries for full functionality, I strongly recommend that you use one of the open-source package distributors (MacPorts, Homebrew, or Fink) for OS X to install everything you need, including Django, Python, PIL, MySQL or PostgreSQL. In the long run you will almost certainly save yourself lots of time and headaches since they've figured out how to easily install, update, and delete hundreds of components that should just play together. – Ned Deily Apr 04 '13 at 03:58