_imaging C module error in python PIL

ely picture ely · May 27, 2011 · Viewed 10.9k times · Source

I have read the other posts about the notorious _imaging C module error when installing PIL on Mac OS X and none of the solutions provided anywhere, including the PIL FAQ, have proven helpful.

I have the newest versions of libjpeg and zlib freshly installed from source. I have edited the Makefiles in each of these to include the option -arch i386 in the LD_FLAGS variable for 32-bit builds. PIL installs with no problems of any kind and the install summary printed to the terminal says that JPEG, TIFF, and PNG support are all OK. After that I try the self test:

new-host:Imaging-1.1.7 ely$ python selftest.py 
*** The _imaging C module is not installed

This is commonly seen for a variety of reasons. Probing deeper, here I try to import _imaging directly in python.

new-host:Imaging-1.1.7 ely$ python
ActivePython 2.7.1.4 (ActiveState Software Inc.) based on
Python 2.7.1 (r271:86832, Feb  7 2011, 11:33:10) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> 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/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/_imaging.so
  Expected in: dynamic lookup

Here again, the 'Symbol not found: _jpeg_resync_to_restart' is notorious and common, and many people have suggested this has to do with incorrect path to libjpeg. I've checked again and again and I only have libjpeg (as well as zlib, etc.) installed in my home directory, all in separate folders, from source, and all of this is marked correctly in the file setup.py.

So, PIL should be getting its jpeg support (and zlib, etc.) from the right places. All the dependencies are installed. I can see _imaging.so in my sys.path, yet I still get this _jpeg_resync_to_restart error.

Are there any ideas that don't link to alternate posts? I have spent ~7 hours reading and trying possible solutions from posts in every forum I can find.

Answer

ApPeL picture ApPeL · Jul 27, 2011

Since you have been trying this a few times, I recommend running a few commands to clean out the old items first and start from the beginning.

I used jpeg v8c and Imaging 1.1.6 on Mac OS X, 10.6 and 10.7

get v8c of jpeg cd into jpeg directory.

sudo make clean
CC="gcc -arch i386" ./configure --enable-shared --enable-static
make
sudo make install

get imaging i am using 1.1.6

untar cd into imaging

sudo rm -rf build
vi setup.py
JPEG_ROOT = libinclude(“/usr/local/lib”)
sudo python setup.py install

And it’s that simple

Run your python interpreter,

import PIL
import _imaging
import Image

if all is well, then your all set.

Here is the full article on my blog Python 2.7, OSX Lion, PIL and Imaging