簡體   English   中英

使用cx_freeze制作exe時出現EnsureDispatch錯誤

[英]EnsureDispatch error when using cx_freeze for making exe

我正在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}'

我只是無法在這里解決問題。 請幫助。

謝謝。

您正在使用在磁盤上生成的靜態代理,該靜態代理具有編譯后的可執行文件查找問題。 如果您不知道靜態代理是什么,則可能使用的是win32com.client.gencache.EnsureDispatch ,它會自動生成靜態代理。

解決此問題的最簡單方法是使用win32com.client.dynamic.Dispatch使用動態代理。 靜態代理有一些好處,但是您很有可能不需要它。

您可以在此處找到有關COM對象的靜態和動態代理的更多信息: http : //timgolden.me.uk/python/win32_how_do_i/generate-a-static-com-proxy.html

我剛剛發現, 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

參考文獻:

使用靜態調度,PS性能要好得多

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM