Need a little more help with py2exe/COM problem.

Marc mnations at airmail.net
Wed Oct 22 15:52:02 EDT 2003


Hello,

I've fiddled with this for quite a while and thought I had the problem
solved. I had a version that would successfully compile and run. But
then I had to change the code to use a different module, and now it
will compile but not run again.

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.

WHAT WORKED
===========
import win32com.client
import win32com.client.dynamic
import os, os.path

class easyExcel:
    def __init__(self, filename=None):
        self.xlApp =
win32com.client.dynamic.Dispatch('Excel.Application')
        self.filename = filename
        ...much more stuff...

WHAT DOESN'T WORK
=================
import win32com.client
import win32com.client.dynamic
import os, os.path

class ExcelEvents:
    def getHandle(self, ee):
        self.ee = ee
    def OnWorkbookBeforeClose(self, wb, wn):
        if self.ee.active():
            print "WORKBOOK IS ACTIVE"
            self.ee.hide()
            return 1
        else:
            print "WORKBOOK IS NOT ACTIVE"
            return 0

class easyExcel:
    def __init__(self, filename=None):
        self.xlApp =
win32com.client.dynamic.Dispatch('Excel.Application')
        x_events = win32com.client.WithEvents( self.xlApp, ExcelEvents
)
        x_events.getHandle(self)


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

I get the same error if I use "DispatchWithEvents" from the *client*
module instead of using "Dispatch" and "WithEvents".

Does anyone know why this happens? Why does it work with one module
and not the other one? And is there something special I need to do
while running py2exe to include this module?

Thanks ahead of time for any help,
Marc




More information about the Python-list mailing list