Installing PIL: use pip instead of easy_install

A quick one, since it took me a bit of googling to find the answer.

It seems that there’s something amiss with the packaging of PIL (the Python Imaging Library) if you use easy_install to install it. The error you’ll get when you try to import PIL is:

 Traceback (most recent call last):
  File “<stdin>”, line 1, in <module>
ImportError: No module named PIL

Using pip to remove and then re-install it worked for me:

pip uninstall PIL
pip install PIL

(BTW if you’re using virtualenv, then you already have pip.)

Before you get too excited though, try the following in the Python interpreter:

import _imaging

If you get the following error, and you’re on a Mac, it’s because of an architecture clash between your libjpeg and the PIL build:

Traceback (most recent call last):
  File “<stdin>”, line 1, in <module>
ImportError: dlopen(/blah/blah/python2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
  Referenced from: /blah/blah/python2.6/site-packages/PIL/_imaging.so
  Expected in: flat namespace
 in /blah/blah/python2.6/site-packages/PIL/_imaging.so

My understanding of what’s going on is that Python is a 64-bit (x86_64) application attempting to dynamically load a 32-bit (i386) shared library, which fails.

Anyway – I had libjpeg installed via the fink package manager. I removed it and installed it with homebrew instead, and the problem went away:

brew install jpeg

If that doesn’t work for you, this thread may have an answer.

Update: I’ve since found out about Pillow, which appears to be a maintained PIL fork. Might be one to check out.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: