Install PIL in Snow Leopard

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. :)

Comments:

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.

Post your comment:

Author:

  • chaiwat

Archives:

Powered by Django.