[Image-SIG] PIL and py2exe

Fredrik Lundh fredrik at pythonware.com
Mon Aug 29 16:07:14 CEST 2005


Sean Curtis wrote:

> the initialization of PIL does two things that are banging heads with 
> py2exe:
>
> 1) It always imported Tk "just in case".

the exact code is

try:
    # give Tk a chance to set up the environment, in case we're
    # using an _imaging module linked against libtcl/libtk (use
    # __import__ to hide this from naive packagers; we don't really
    # depend on Tk unless ImageTk is used, and that module already
    # imports Tkinter)
    __import__("FixTk")
except ImportError:
    pass

I could have sworn that py2exe didn't treat calls to __import__ as re-
quired modules, but I might be wrong, or maybe they've changed this
in recent versions.

> Even if I'm not using Tk, Tk is imported.
> This causes py2exe to load everything in Tk causing my install to get 
> ridiculously
> huge.  Is there any way around this?

use the "ignores" option to py2exe.  this is described on the py2exe wiki:

http://starship.python.net/crew/theller/moin.cgi/Py2Exe

(see section 1.1)

> 2) The file format modules are imported on the sly using the __import__ 
> function
> and constructing the module names at runtime (or at least at compile 
> time.)  Be-
> cause of this, py2exe doesn't recognize module dependencies and I get a
> distribution with no file plugins (and thus, the ability to read NOTHING.)

this too is described on the py2exe wiki:

http://starship.python.net/crew/theller/moin.cgi/PIL_20and_20py2exe

</F> 





More information about the Image-SIG mailing list