By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,838 Members | 1,668 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,838 IT Pros & Developers. It's quick & easy.

Need a little more help with py2exe/COM problem.

P: n/a
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.Applicatio n')
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.Applicatio n')
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
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <mn******@airmail.net> wrote in message
news:43**************************@posting.google.c om...
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.Applicatio n')
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.Applicatio n')
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

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.