Issue #108 resolved

PIL/Pillow isn't using its required libraries to open images

Brandon Aubie
created an issue

Although I can see that libtif et al. are in the created package, whenever I try to open an image (except PNG, which matplotlib supports natively), I get the following error:

Traceback (most recent call last):
  File "gui.pyc", line 83, in open_image
  File "gui.pyc", line 86, in load_image
  File "glowreader.pyc", line 75, in load_image
  File "/Users/brandon/Development/glowreader/macosx/dist/", line 2031, in imread
    return _imread(*args, **kwargs)
  File "/Users/brandon/Development/glowreader/macosx/dist/", line 1220, in imread
    im = pilread(fname)
  File "/Users/brandon/Development/glowreader/macosx/dist/", line 1200, in pilread
    image =
  File "PIL/Image.pyc", line 2020, in open
OSError: cannot identify image file

The code works fine on my system so it looks like PIL simply can't find the image libraries.

Comments (8)

  1. Brandon Aubie reporter

    To add more information, I had originally installed Pillow via macports. I uninstalled it from there and re-installed it from source. I get the same problem in both cases.

  2. Ronald Oussoren repo owner

    I can reproduce the problem with a simple script that tries to open a hardcoded imagefile (some random JPEG file on my laptop).

    Sigh. This appears to be related to the vagueness of module names in PIL, that is is it 'PIL.Image' or 'Image'? In Pillow this is supposed to be solved by always having to use PIL.Image, but the PIL.Image module still loads all plugins as if they are at the toplevel (first add the directory for the PIL package to sys.path, then import JpegImagePlugin (and others), then restore the original sys.path again. Futhermore PIL.Image.init() uses os.listdir to find the list of plugins, and that won't work when PIL/Pillow is added to a zipfile.

    py2app contains some code to workaround the latter issue, but without updating sys.path and because of that the workaround doesn't work correctly for Pillow.

    I'm working on a fix.

  3. Ronald Oussoren repo owner

    Changeset be78bb01dc96 in the 0.7 branch contains an updated PIL recipe that works better with Pillow. The JPEG image plugin doesn't work yet due to the way abuses the import system, an easy workaround for that is to patch PIL.JpegImagePlugin, look for "from JpegPresets import" and change that to "from PIL.JpegPresets import".

    I'm pretty sure that I can coax py2app into loading that plugin correctly as well, but that will have to wait until the end of the day.

    See also

  4. Ronald Oussoren repo owner

    It should now actually be possible to use Pillow with Python 3 and py2app (Both in the 0.7 branch and the default branch).

    I've tested this with a script that loads a single JPEG and prints some information about it.

    The PIL recipe is fairly ugly, but that can't be helped given the way PIL/Pillow looks for image format plugins.

  5. Log in to comment