Differences between revisions 4 and 5
Revision 4 as of 2006-02-28 03:30:38
Size: 2333
Editor: h-66-134-92-2
Comment: Added comment to code for handling 0.6.4
Revision 5 as of 2006-02-28 04:02:58
Size: 2351
Editor: h-66-134-92-2
Comment: Make the 0.6.4 version the default
Deletions are marked like this. Additions are marked like this.
Line 44: Line 44:
    import modulefinder # in 0.6.4 use "import py2exe.mf as modulefinder"     import py2exe.mf as modulefinder # in py2exe < 0.6.4 use "import modulefinder"
Line 70: Line 70:
    import modulefinder # in 0.6.4 use "import py2exe.mf as modulefinder"     import py2exe.mf as modulefinder # in py2exe < 0.6.4 use "import modulefinder"

The Problem

I used [http://tgolden.sc.sabren.com/python/winshell.html winshell] from Tim Golden - a thin wrapper around Windows Shell-Functions.

winshell.py starts with

   1 from win32com import storagecon
   2 from win32com.shell import shell, shellcon

py2exe learns, that something is missing:

The following modules appear to be missing
['Interface', 'intSet', 'mxDateTime.__version__', 'win32com.shell']

and starting the programm leaves:

Traceback (most recent call last):
  File "xxxxxx.py", line 33, in ?
  File "xxxxxxx.pyo", line 9, in ?
  File "winshell.pyo", line 27, in ?
ImportError: No module named shell

in the log.file.

Explanation

win32com does some magic. There really is no win32com.shell anywhere.

Solution

Without shame I browsed [http://cvs.sourceforge.net/viewcvs.py/spambayes/ spambayes source code] and found:

   1 # ModuleFinder can't handle runtime changes to __path__, but win32com uses them,
   2 # particularly for people who build from sources.  Hook this in.
   3 try:
   4     import py2exe.mf as modulefinder # in py2exe < 0.6.4 use "import modulefinder"
   5     import win32com
   6     for p in win32com.__path__[1:]:
   7         modulefinder.AddPackagePath("win32com", p)
   8     for extra in ["win32com.shell","win32com.mapi"]:
   9         __import__(extra)
  10         m = sys.modules[extra]
  11         for p in m.__path__[1:]:
  12             modulefinder.AddPackagePath(extra, p)
  13 except ImportError:
  14     # no build path setup, no worries.
  15     pass

I just added that in top of my setup.py file:

   1 # By default, the installer will be created as dist\Output\setup.exe.
   2 
   3 import time
   4 import sys
   5 
   6 # ModuleFinder can't handle runtime changes to __path__, but win32com uses them
   7 
   8 try:
   9     import py2exe.mf as modulefinder # in py2exe < 0.6.4 use "import modulefinder"
  10     import win32com
  11     for p in win32com.__path__[1:]:
  12         modulefinder.AddPackagePath("win32com", p)
  13     for extra in ["win32com.shell"]: #,"win32com.mapi"
  14         __import__(extra)
  15         m = sys.modules[extra]
  16         for p in m.__path__[1:]:
  17             modulefinder.AddPackagePath(extra, p)
  18 except ImportError:
  19     # no build path setup, no worries.
  20     pass
  21 
  22 from distutils.core import setup
  23 import py2exe

And this worked.

win32com.shell (last edited 2021-08-24 23:35:23 by JimmyRetzlaff)