Using PIL with py2exe

Miki Tebeka miki.tebeka at zoran.com
Mon Dec 15 04:40:35 EST 2003


Hello David, 

> >Does anyone know how to embed PIL into a py2exe program.
> >
> >As far as I can tell PIL is not finding its plugins for Image I/O,
> >they are imported dynamically as required. So I cant load or save
> >pictures
> PIL imports the drivers dynamically, so py2exe doesn't find them.
> Including these lines should solve your problem.
> 
> ## Static imports from PIL for py2exe
> from PIL import GifImagePlugin
> from PIL import JpegImagePlugin
I had the same problem, created a script call pil2exe which I import in my modules.

--- pil2exe.py ---
'''Fix allowing PIL to work under py2exe'''

__author__ = "Miki Tebeka <mikit at zoran.co.il>"
# $Id: pil2exe.py,v 1.2 2003/10/20 11:35:38 mikit Exp $

#FIXME: 
# Hand pick only the modules you need (currently all *Plugin.py from PIL
# directory are imported)

#FIXME: Find who's the criminal and why, currently disable warnings
import warnings
warnings.filterwarnings("ignore")

import ArgImagePlugin
import BmpImagePlugin
import CurImagePlugin
import DcxImagePlugin
import EpsImagePlugin
import FliImagePlugin
import FpxImagePlugin
import GbrImagePlugin
import GifImagePlugin
import IcoImagePlugin
import ImImagePlugin
import ImtImagePlugin
import IptcImagePlugin
import JpegImagePlugin
import McIdasImagePlugin
import MicImagePlugin
import MpegImagePlugin
import MspImagePlugin
import PalmImagePlugin
import PcdImagePlugin
import PcxImagePlugin
import PdfImagePlugin
import PixarImagePlugin
import PngImagePlugin
import PpmImagePlugin
import PsdImagePlugin
import SgiImagePlugin
import SunImagePlugin
import TgaImagePlugin
import TiffImagePlugin
import WmfImagePlugin
import XVThumbImagePlugin
import XbmImagePlugin
import XpmImagePlugin
--- pil2exe.py ---

Use at your own risk :-)

HTH.
Miki




More information about the Python-list mailing list