Getting the Python image library (PIL) module to work on a Mac


"Installing" version 1.1.7 of the Python Image Library (PIL) on a Mac with IntelCPU 

The zip file in http://www.vrac.iastate.edu/~charding/HCI574_lecture_notes/PIL1.1.7_for_intel_Mac/ contains the PIL 1.1.7 module that I compiled on my intel Mac (Snow Leopard). Sadly, there's no nice installer for PIL on Mac, and, at least for the moment, I don't have time to investigate how to make a Mac installer (.mpkg file) myself. For now  "installing" PIL on your Intel Mac requires that you manually copy my compiled PIL folders into your site-packages folder,  For me the path is: 
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages but it may be different for you, so you should do the following:

  • In Idle, use File-Path Browser, and look for a path ending in site-packages (which will very likely contain packages such as numpy and matplotlib already) and note this path.
or 
  • in a Python shell type: import syssys.path and you should see a lot of paths, note the one that ends in site-packages or paint it with your mouse and copy with Cmd-C (no quotes!)

OK, so now that you know the path to your site-packages folder, let's get my pre-compiled  PIL1.1.7 module and copy it into your site-packages folder:

To open a Finder window to  your site-packages folder do this: 
  • Finder - Go - Goto Folder and either type or paste your site-packges path in
  • press OK 
  • it should open your site-packages folder, keep it open
  • copy both, the PIL folder and a PIL.pth file from the PIL1.1.7_i386 folder into your site-packages folder
Test if python can now use PIL by typing this into a new python shell (also see PIL_test.py)

import Image # Image is PIL's main module
im = Image.open("HCI.jpg") # open jpg, must be in same folder
print im.format, im.size, im.mode # get some info on the jpg image file
im.show() # show it in Preview

if you can see the image in Preview, the PIL module is working - congrats, you got it working!
----------------------------------------------------------------------------------------------------------------

If that doesn't work, here are some possible solutions:
  • check if you really copied both, the PIL folder and a PIL.pth file from the PIL1.1.7_i386 folder into your site-packages folder
  • quit any python shells (Idle, terminal, Wing, ...) and restart them and the import Image code again
  • Check permissions of the PIL folder in your site-packages folder:
    • Do a Get Info (Cmd-i) on the PIL folder inside you site-packages folder (Snow Leopard only?)
    • check Sharing & Permissions, it (and it's entire content) must be read-able for you. 
    • if not set the permissions to Read or Read & Write). Same for the PIL.pth file
  • Look into: http://www.vrac.iastate.edu/~charding/HCI574_lecture_notes/PIL_old, which contains several older installers/PIL folders that I downloaded last year. 

    unzip PIL1.1.7 Mac 32bit.zip, this will give you a PIL folder and PIL.pth file, copy those to your site-packages folder and see if that works.

    PIL-Tiger-Intel.zip is and older version of PIL (1.1.6?) but it should work for our purposes

    PIL-1.1.7a2-py2.5-macosx10.5.mpkg is a proper installer but it will install it in the Python 2.5 site-package folder (if it even lets you), and you'll have to more the PIL folder and PIL.pth file from there into your 2.6 site-packages folder manually.

April 20- there's a report about my pre-compiled PIL 1.1.7 not working for 64-bit python, one solution to force it to create a 32-bit mode version is to use -i386 :
 arch -i386 python2.6

No comments:

Search This Blog