使用cx_freeze创建exe时,EnsureDispatch错误

时间:2014-11-13 10:53:10

标签: python-3.x exe cx-freeze win32com

我在Windows 7上使用Python 3.4。我的安装文件如下:

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,
    )

当运行获得的exe时,弹出一个错误说:

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

我在这里无法弄清楚问题。求助。

感谢。

2 个答案:

答案 0 :(得分:1)

您正在使用在磁盘上生成的静态代理,并且已找到已编译的可执行文件。如果你不知道静态代理是什么,你可能正在使用win32com.client.gencache.EnsureDispatch自动生成静态代理。

解决问题的最简单方法是使用win32com.client.dynamic.Dispatch使用动态代理。静态代理有一些好处,但很有可能你不需要它。

您可以在此处找到有关COM对象的静态和动态代理的更多信息:http://timgolden.me.uk/python/win32_how_do_i/generate-a-static-com-proxy.html

答案 1 :(得分:1)

我刚刚发现EnsureDispatch的问题在gencache模块内,当使用cx_freeze构建可执行文件时,它假定处于只读模式。

以下行允许在Windows 7 x64中的AppData\Local\Temp\gen_py\#.#\目录中构建缓存:

from win32com.client import gencache
if gencache.is_readonly:
    gencache.is_readonly = False
    gencache.Rebuild() #create gen_py folder if needed

参考文献:

P上。 S.静态调度的性能要好得多

相关问题