Issue #78 resolved

Cannot load PIL

Anonymous created an issue

In Mountain Lion (10.8.2), py2app 0.7.1

PIL works ok for my app when running without py2app (i.e. python but the simple example in py2app/examples/PIL/ does not work.

I wrote my own minimal app which simply calls print "hello". I found that the app created by py2app will throw an error on launch. This happens even if there is no import PIL in my code. All that is needed to get the error on launch is to put 'packages': ['PIL'] in the options in

The error does not occur when I execute python py2app. It occurs when I click on the resulting app and launch it. Like I said, I know PIL is fine because my app runs fine from the command line.

I wish I knew what error was being thrown, but it's not captured in the logs (see issue #77)

Comments (8)

  1. Steve Strassmann

    I'm anonymous no longer

    It looks like a special-purpose PIL recipe has been magically added to in my app. So it looks like merely adding PIL to packages causes the PIL recipe to run.

    I manually edited and commented out the line _recipes_pil_prescript([]). My app runs fine after this.

    How can I disable this recipe? Is there some option I can use?

  2. DanHorner

    I think there is a path problem in the generated app.

    I see this on mountain lion with a couple of other packages: adding wx or serial to 'packages' give similar results. They are included in the application but the import fails at run time.

    I haven't had a chance/reason to chase it down: I just left the packages option out and the resulting app behaved properly.

    This was also with system Python on Mountain Lion

  3. Steve Strassmann

    Packages show up in, but py2app doesn't put this on sys.path by default (perhaps it should?). I added these lines to and my app works fine:

    ROOT = os.path.dirname(__file__)

    So basically, adding PIL to packages places it in, which is good, but I need the hack above to run it. The _recipes_pil_prescript tries to import PIL in, which runs before has a chance to fix sys.path, so it fails.

    So I really don't need _recipes_pil_prescript at all. Is there any option to leave it out? I have to manually edit after every build, which is sort of tedious.

  4. Ronald Oussoren repo owner

    This last message points to the root cause of this issue: for some reason the directory with PIL is not added to sys.path.

    The code in the PIL recipe is older than my involvement with py2app, and I'm not entirely sure what that code tries to accomplish. Just looking at the code it seems to try to make it possible to use PIL when it is added to the zipfile.

    Have you tried removing 'PIL' from the packages option? With some luck py2app will then to the right thing.

    The easiest way to disable to code added to

    • Locate 'py2app/recipes/PIL/' in the source or installation tree of py2app

    • Look for 'prescripts = [' in that file (should be near the end) and add '#' to the start of that line. This will disable adding code to

    BTW. PIL is slightly annoying from a packaging view: it does some trickery to ensure that both 'import Image' and 'import PIL.Image' work. This might confuse py2app (but I consider that confusion a bug in py2app).

    (update: fixed markup)

  5. Ronald Oussoren repo owner

    I cannot reproduce this with my own installation of python 2.7 on OSX 10.8.2

    • py2app from repository (default branch)
    • fairly recent build of python 2.7 (framework, i386/x86_64 architectures, 10.8 SDK)
    • Imageing 1.1.7 with jpeg, tiff, freetype and lcms support

    the example in py2app/examples/PIL works for me (but doesn't do anything)

    However: I am able to reproduce the issue when using /usr/bin/python.

  6. Ronald Oussoren repo owner

    I'm only able to reproduce the issue when explictly includeing 'PIL', the example works fine when I don't add a packages=['PIL'] line to the py2app options.

    This is a bug in the way semi-standalone bundles are created, the python packages that are added using the packages option aren't on sys.path.

    I have a fix, but won't commit until I have created a testcase for this issue.

  7. Ronald Oussoren repo owner

    Note w.r.t. issue #77 (mentioned in the bug report): that's caused by a change of behavior in OSX.

    I've added some more information to #77, including a possible way to work around this change in py2app. That will require changes to the C code of py2app.

  8. Log in to comment