views:

241

answers:

3

I'm working on making a py2exe version of my app. Py2exe fails at copying some modules in. My original app loads .png files fine, but the exe version does not:

Traceback (most recent call last):
  File "app.py", line 1, in <module>
    from gui.main import run
  File "gui\main.pyc", line 14, in <module>

  File "gui\controllers.pyc", line 10, in <module>

  File "gui\utils\images.pyc", line 78, in <module>
    ☺
  File "gui\utils\images.pyc", line 70, in GTK_get_pixbuf
    ☺§☺▲☻
  File "gui\utils\images.pyc", line 38, in PIL_to_pixbuf

gobject.GError: Image type 'png' is not supported

Any idea what I should force py2exe to include?

+2  A: 

What platform is this? Lately I think they improved the png support on windows, so the version of pygtk you're using is pertinent also. http://aruiz.typepad.com/siliconisland/2008/02/goodbye-zlib-li.html

pixelbeat
It's Python 2.5, and I think the latest pygtk version - 2.12.9. The thing is, it works normally; it just fails once I try to turn it into an exe
Claudiu
ah i see a problem with it not finding the pixbuf loader module file...
Claudiu
I would guess that you have the older version that needs zlib and libpng dlls. Have you specified those for inclusion?
pixelbeat
I just realized that myself. I haven't, actually - how do I tell py2exe to include them? Or should I just do a manual copy of them into the dst directory?
Claudiu
+4  A: 

This is a known problem with PIL and py2exe

PIL (python image library) imports its plugins dynamically which py2exe doesn't pick up on, so it doesn't include the plugins in the .exe file.

The fix (hopefully!) is to import the drivers explicitly like this in one of your .py files

import Image
import PngImagePlugin
Image._initialized=2

That will mean that py2exe will definitely include the plugin. The Image._initialized bit stops PIL scanning for more plugins.

Here are the docs from the py2exe wiki explaining this in full

Nick Craig-Wood
I am suspecting that this is entirely unrelated.
Ali A
+2  A: 

Make sure you bundle the loaders when you install your application. Py2exe won't know about these, but they are a needed part of GTK, and live where the rest of the GTK "data" files live.

From http://unpythonic.blogspot.com/2007/07/pygtk-py2exe-and-inno-setup-for-single.html

It is not sufficient to just make py2exe pull in the GTK DLLs for packaging (which it does pretty successfully). GTK also requires a number of data files which include themes, translations etc. These will need to be manually copied into the dist directory so that the application can find them when being run.

If you look inside your GTK runtime directory (usually something like c:\GTK) you will find the directories: share, etc, lib. You will need to copy all of these into the dist directory after running py2exe.

Copyright retained.

Ali A