py2exe'd version of GTK app can't read png files
Question
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?
Solution
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
OTHER TIPS
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
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.