Py2exe executable not loading images
Thomas Heller
thomas.heller at ion-tof.com
Fri Oct 11 09:26:09 EDT 2002
anandpillai6 at yahoo.com (Anand) writes:
> I have a simple viewer class in python using wxPython and PIL.
> The code uses PIL Image class to open an image and wxPython classes
> namely wxFrame, wxBitmap, wxImage to paint it on to a wxPanel.
[...]
>
> The code works fine for all images when run as a python script.
> When I create a win32 executable using py2exe and setup.py, the
> Image class fails with a message <reproduced here>
>
> <Quote>
> File "<string>", line 453, in OpenImage
> File "PIL\Image.pyc", line 960, in open
> IOError: cannot identify image file
> </Quote>
>
A simple Web search finds several pages offering solutions to this
problem. The best one I could find is from douglas zongker:
http://www.cs.washington.edu/homes/dougz/slithy/py2exe/
He writes:
Statically load PIL image formats. Slithy uses the Python Imaging
Library to read image files. Normally PIL dynamically loads plugins
for the different file formats as it needs them; this scheme won't
work with py2exe. At the top of your main script, add a blob of
code that looks like this:
import Image
import JpegImagePlugin # import drivers for every image format you use
import TgaImagePlugin
import PngImagePlugin
import GifImagePlugin
Image._initialized = 1
HTH,
Thomas
More information about the Python-list
mailing list