installing PIL on Snow Leopard

I’ve added the ability to extract and upload images to my post-with-markdown script. Unfortunately, markdown doesn’t have short codes for setting the size of a displayed I could solve this problem by using a full image tag in the post. Or, I can upload multiply sized versions of the image, and call in the post the one that I want. As a coding experiment, I decided to do the latter. Also, for the simplicity of the script it’s easier to upload a single mime type. Since I’m most often, though not exclusively, uploading screen shots, it just seems easier to use .png files.

Both of these tasks — resizing images and switching formats — are easy to accomplish using the Python Imaging Library. Getting PIL up and running on Snow Leopard, not so much. I first installed using easy_install, and everything seemed to be working fine except for jpeg encoding/decoding. I apparently didn’t have libjpg installed. So, I used macports to install the library with $ sudo port install jpeg. After that, I needed to reinstall PIL. I uninstalled the library using pip (I don’t know why I did it that way instead of with easy_install.) Then, I reinstalled PIL with pip and, low and behold, jpeg encoding was available and fine, but PIL’s _imaging C libraries stopped working. Grrr. I tried tons of ways around this, but simply couldn’t figure out one that worked.

What finally worked was a two-step process in Emotu Balogun’s comment on the top rated answer to this stackoverflow question. Apparently the problem has to do with incompatibilities of the gcc version, libjpeg, and PIL. At any rate, this worked for me:

  1. Reinstall libjpeg with Macports and adding the +universal argument to the command: $ sudo port install jpeg +universal.

  2. Install PIL with Macports in the same manner: $ sudo port install py26-pil +universal.

  3. I use Snow Leopard’s default 2.6.1 python installation, so I copied the PIL package from Macports’ site-packages folder in /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages to Snow Leopard’s default site-packages library.

After doing that, PIL is working. Worth it? Not so sure. But, with PIL I can convert all of my images for this blog to .png files, and also resize the images to upload one that will fit in the dimensions of my posts.

About

Associate Professor of Early Latin America Department of History University of Tennessee-Knoxville

Tagged with: ,
Posted in programming
One comment on “installing PIL on Snow Leopard
  1. Eric Pavey says:

    Thanks for the post: I’d been slamming my head into the wall trying to get the exact same config setup…. kept getting gcc compiler errors, missing _imaging library, etc. It took about half an hour to build all the dependencies, but amazingly PIL works now. I’m always amazed how on the mac some things are really easy, and others, like this, are surprisingly hard…

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

parecer:
parecer:

Hacer juicio ú dictamen acerca de alguna cosa... significando que el objeto excita el juicio ú dictamen en la persona que le hace.

Deducir ante el Juez la accion ú derecho que se tiene, ó las excepciones que excluyen la accion contrária.

RAE 1737 Academia autoridades
Buy my book!



Chad Black

About:
I, your humble contributor, am Chad Black. You can also find me on the web here.
%d bloggers like this: