Search code examples
python-3.xexecx-freezewin32com

EnsureDispatch error when using cx_freeze for making exe


I am working with Python 3.4 on Windows 7. My setup file is as follows:

from cx_Freeze import setup, Executable, sys

exe=Executable(
 script="XYZ.py",
 base="Win32Gui",

 )
includefiles=[]
includes=[]
excludes=[]
packages=[]
setup(

 version = "1.0",
 description = "XYZ",
 author = "MAX",
 name = "AT",
 options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
 executables = [exe]
 )


from distutils.core import setup
import py2exe, sys, os, difflib

sys.argv.append('py2exe')
setup(
    options = {'py2exe': {'bundle_files': 1}},
    console = [{'script': "XYZ.py"}],
    zipfile = None,
    )

When the obtained exe is run, an error pops up saying:

...
File "C:\Python34\Lib\site-packages\win32com\client\CLSIDToClass.py", line 46, in GetClass
    return mapCLSIDToClass[clsid]
KeyError: '{00020970-0000-0000-C000-000000000046}'

I just can't figure out the problem here. Help, please.

Thanks.


Solution

  • You are using static proxy which is generated on your disk and which has the compiled executable trouble finding. If you do not know what the static proxy is, you are probably using win32com.client.gencache.EnsureDispatch which generates static proxy automatically.

    The easiest way to fix the problem is to use dynamic proxy by using win32com.client.dynamic.Dispatch. Static proxy has some benefits, but there is a high possibility that you do not need it.

    You can find more information about static and dynamic proxies to COM objects here: http://timgolden.me.uk/python/win32_how_do_i/generate-a-static-com-proxy.html