It seems like many people install PIL in Snow Leopard but the installed library can't open any Jpeg file. Today I try to fix that problem in a Macbook that just upgraded its OS to Snow Leopard (so we have to install everything again).
First, I found that the Macbook owner already install libjpeg via fink (http://www.finkproject.org/). Unfortunately, libjpeg in fink was pre-compiled without --enable-static which required by PIL.
So, my solution is so simple. I just uninstall the libjpeg that came with fink by:
$ sudo apt-get uninstall libjpeg-shlibs
If you already installed other packages that require libjpeg and libjpeg-shlibs they will be removed also. However, if you really need a functioning PIL, you have to do this.
Next, I download libjpeg latest version (http://www.ijg.org/files/jpegsrc.v7.tar.gz), untar it, and configure it:
$ tar zxvf jpegsrc.v7.tar.gz $ cd jpeg-7 $ ./configure --enable-shared --enable-static $ make $ sudo make install
Now, you just installed libjpeg into /usr/local/lib. So, it's time to install PIL. Download the PIL source code from http://effbot.org/downloads/Imaging-1.1.6.tar.gz then untar it:
$ tar zxvf Imaging-1.1.6.tar.gz $ cd Imaging-1.1.6
This is the trick, you must open setup.py with your prefered text editor then looking for the line JPEG_ROOT = None and then it to JPEG_ROOT = libinclude("/usr/local") then save the file and continue:
$ python setup.py build
If everything fine, you can install PIL to your system library. If the PIL need something that didn't exist, it will tell you on the error message. You may install the missing library via fink or download and compile it by yourself. Then install the PIL as root:
$ sudo python setup.py install --optimize=1
Done. :)

Even with your excellent instructions I kept having a problem with my PIL installation. The "Symbol not found: _jpeg_resync_to_restart error" occurred when trying to import the imaging library.
I described what was wrong with my installation here:
http://www.brambraakman.com/blog/comments/installing_pil_in_snow_leopard_jpeg_resync_to_restart_error/
Thank you !!! I cannot live without PIL.
Sadly, this didn't work for me. I thought it would but it didn't.
I managed to install on Snow Leopard a bit more simply by putting the downloaded tar file in /Library/Python/2.6/site-packages and typing
tar -xvpf Imaging-1.1.6.tar
then cd into the directory and
sudo python setup.py install.
It works when self tested and when called up by biopython (through ReportLab). I didn't have previous installations of python tools other than those two, though.
Works for me, thanks!
FYI, I have the default 64 bit Python 2.6.1 that comes with SL, and couldn't import _imaging after doing a regular build & install of libjpeg and PIL. In my case, I didn't have to touch the existing dynlibs in /usr/local/lib
Thanks for your very clear instructions Cliff. It didn't work for me - possibly because I have an Intel Mac? I have to admit to being fairly ignorant of these kinds of instals having been spoiled by all the no-brain installers over the years.
This worked for me when nothing else would! Thank you very much!
Our solution to the "Symbol not found: _jpeg_resync_to_restart" error is explained here:
http://www.arnebrodowski.de/blog/libjpeg-symbol-not-found-error-with-pil-on-10.6-snow-leopard.html
Thanks for posting this! It worked great for me, and was very easy to follow.
Your instructions are as clear as can be. But they didn't work for me. I'm running Python 2.6.5 on SL 10.6.3.
The only way I could get this to work was to use MacPorts (http://www.macports.org/install.php). I installed it and used the following:
Before I could make MacPorts work, I had to manually remove the following jpeg files (do this at your own risk, but worked for me):
cd /opt/local/bin/
sudo rm -rf *jpeg*
sudo rm -rf *jpg*
cd /opt/local/include/
sudo rm -rf *jpeg*
sudo rm jconfig.h
sudo rm jerror.h
sudo rm jmorecfg.h
cd /opt/local/lib
sudo rm libjpeg.a
sudo rm libjpeg.*
cd /opt/local/share/man/man1/
sudo rm -rf *jpeg*
sudo rm -rf *jpg*
Then, Finally...I was able to get it to work:
sudo port install jpeg +universal
Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> import _imaging
Worked like charm :-) even with PIL 1.1.7
Thanks!
Missing step for me was provided by http://mtrichardson.com/2009/11/pil-libjpeg-snow-leopard-and-missing-_jpeg_resync_to_restart/
I built jpeg-8b with "CC="gcc -arch i386" ./configure --enable-shared --enable-static", then rebuilt PIL. import _imaging now works! Now i just need somebody to explain why...
Thank you !!! I cannot live without PIL
Sweet work.