python - py2exe converted script does not run win32com.client correctly



I have seen a couple posts related to my issue on other sites, but nothing worked. To make a long story short, my program importa win32com.client to access Microsoft Word. I create a standalone executable using py2exe and every time the user selects the option to open MS Word I get a KeyError. Below is the code which the compiler claims the error is:

# Call the MS Word app
MS_Word = win32com.client.gencache.EnsureDispatch('Word.application')

And below is the result when the program run this particular line:

Exception in Tkinter callback
Traceback (most recent call last):
File "Tkinter.pyc", line 1536, in __call__
File "PROTOTYPE_PCE.PY", line 46, in SCAN
File "win32com\client\gencache.pyc", line 544, in EnsureDispatch
File "win32com\client\CLSIDToClass.pyc", line 46, in GetClass
KeyError: '{00020970-0000-0000-C000-000000000046}'

I am using Tkinter as well, but it is NOT the source of the issue. Opening MS Word from the program is a new feature I have added and it only fails when I create the standalone application. I have also tried Pyinstaller and I my line of errors only increased. Thanks in advance!

1 Answer: 

OKAY! So for some reason the file that py2exe creates after being run does not allow for modules like win32com.client to import into the program. Why? I really do not know I am a noob at this stuff. Anyway the following solution works VERY well, as if I initially had no problem at all. This is what should be included in the script. Taken from another post. I hope this helps someone :)


options={"py2exe": {"skip_archive": True}})

Ignoring in py2exe