Need a little more help with py2exe/COM problem.

Tony Meyer t-meyer at ihug.co.nz
Wed Oct 22 20:46:03 EDT 2003


> I know that functionality in this area is not fully supported 
> yet, but there has to be someone out there that has got this 
> to work. I am using Python2.3, with py2exe 0.4.2, and 
> win32all 159. The fact that this works with one module and 
> not the other is very confusing.

A real PITA, isn't it ;)  From what I've heard, a new py2exe will be out
pretty soon, and as well as being able to use the zipimport stuff, it should
be much better with COM as well (since it's being used for SpamBayes, it'll
have to ;)

[...]
> For some reason when I use the *dynamic* module, I am able to 
> freeze and run perfectly. However, when I use the *client* 
> module functions, I get the following error:
> 
> ImportError: No module named 
> win32com.gen_py.00020813-0000-0000-C000-00000000004
> 6x0x1x4

One thing that made a major difference for me was moving the gen_py
directory back into the win32com one (in Lib/site-packages) rather than in
the temp directory where it is stored by default these days (if you look at
the source of win32com.gen_cache there are comments in which Mark says that
it's bad for the gen_py directory to be there, but not why, and it works
much better there from my experience.  The code explains the various ways to
move it back there.  This was the major fix when I had the above problem.

I've also got this in setup.py, although I'm not 100% about how much help
it's giving:
"""
# ModuleFinder can't handle runtime changes to __path__, but win32com uses
them,
# particularly for people who build from sources.  Hook this in.
try:
    import modulefinder
    import win32com
    for p in win32com.__path__[1:]:
        modulefinder.AddPackagePath("win32com", p)
    for extra in ["win32com.shell", "win32com.client"]:
        __import__(extra)
        m = sys.modules[extra]
        for p in m.__path__[1:]:
            modulefinder.AddPackagePath(extra, p)
except ImportError:
    # no build path setup, no worries.
    Pass
"""

Using the -progids switch to py2exe might have helped too - I tried that
before moving the gen_py directory, and it didn't fix it, but I didn't
remove it after moving the directory.

=Tony Meyer






More information about the Python-list mailing list