Installer vs py2exe: Windows DLLs

David Bolen db3l at fitlinxx.com
Fri May 31 15:02:29 EDT 2002


Paul Moore <gustav at morpheus.demon.co.uk> writes:

> When building a distribution for the same script using Gordon
> McMillan's Installer and py2exe, I notice that Installer includes
> PyWinTypes22.dll and win32api.pyd, whereas py2exe doesn't. Both
> executables run fine, so these 2 DLLs are clearly not needed in
> practice.

"Clearly" is in the eye of the beholder - presumably your current
application doesn't need them, but it may not be globally the case.

At least before Python 2.2, there used to be a conditional import of
win32api in the ntpath.py library module (in 2.2 that accesses a
built-in nt module function).  Since installer can't tell whether
you'll execute that code at runtime, it looks at it like a normal
import.  I think with the installer 4 code, win32api used to be a
default exclusion because of this, but that can also get you into
trouble if you wanted it.  I'm not sure if that's why py2exe isn't
finding it.

I'm also not entirely certain why you're finding it with 2.2 (given
your PyWinTypes22.dll link I'm assuming you're using 2.2) unless
there's some other module involved in your application that also
conditionally uses it.

Oh, and I expect the reason you're getting PyWinTypes22.dll is that
once win32api is chosen, it has a binary DLL dependency (e.g., Windows
DLL) to PyWinTypes22.dll.

> Why is there a difference, and can Installer be made to exclude these
> two files when they are not needed, as py2exe does?

If you are sure you don't need it, then you can easily just exclude it
yourself in your spec (installer 5) or cfg (installer 4) files.  I
generally find myself doing this a little with any project anyway
(with installer 5 often to get rid of MSVCIRT since I don't want to
push that out).  Just subtract it out from your COLLECT() call.

> More to the point, in some ways, why does Installer think these files
> are needed? Is there some situation in which py2exe generated
> executables will fail because these files aren't there?

In the case I mention (ntpath) it won't fail because the library
module contains other code that executes when win32api isn't present.
However, because the underlying functionality may not be precisely the
same, you may get slightly different behavior.  If the dependence is
somewhere else, whether the use will change with or without the module
is hard to say.

In general, analysis of Python scripts is inherently a tricky business
because of all the dynamic run-time level operations that can affect
code flow and execution.  There's likely to be some small differences
in such analsys between tools like py2exe and installer, both of which
have some built-in heuristics and pre-configured defaults to try to
handle common cases.  And installer5 has the whole "hook" system to
extend support for special modules known to use dynamic features or
otherwise be difficult to analyse without prior knowledge.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list