Need a little more help with py2exe/COM problem.

M

Marc

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
 
M

Marc

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top