Need a little more help with py2exe/COM problem.

Marc losnations at comcast.net
Wed Oct 22 21:00:09 EDT 2003


Just in case anyone else runs into the same problem, I will post what I got
to work so far.

With Py2.3, py2exe 0.4.2, and win32all 157, I was able to get it to work
doing the following (all of which I had done at one point or another, but
not in the correct order or after I had tried a different version).

Make sure and run makepy.py on Excel.
Compiled with the command: python setup.py py2exe --program
"Excel.Application"

That seemed to work. However I couldn't get it to work using these steps
with win32all 159, and I did create the gen_py directory manually under
win32com.client before running makepy.



"Marc" <mnations at airmail.net> wrote in message
news:4378fa6f.0310221152.6dcba56d at posting.google.com...
> 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