我已经使用 pyinstaller 将 .py 转换为 .exe 文件以分发给我的用户因此我的用户没有安装 Python。
我使用 win32com 打开 excel 并在 excel 中运行宏,这也将打开 SAP
在我的笔记本电脑中我没有问题,但是当我的用户运行 exe 文件时,控制台中会短暂弹出一个错误,然后立即关闭。我必须在 cmd 中运行才能看到下面的错误
File "AutoTQCRevB.5.py", line 76, in <module>
File "win32com\client\dynamic.py", line 543, in __getattr__
pywintypes.com_error: (-2147221168, 'Could not read key from registry', None, None)
所以我检查了模块中的第 76 行
TQCmacrowb = xl.Workbooks.Open(os.getcwd()+ "\\" +TQCfilename)
所以它试图打开excel工作簿。然后我检查了 dynamic.py 第 543 行中的内容
try:
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
except pythoncom.com_error as details:
if details.hresult in ERRORS_BAD_CONTEXT:
# May be a method.
self._olerepr_.mapFuncs[attr] = retEntry
return self._make_method_(attr)
raise
debug_attr_print("OLE returned ", ret)
第 543 行是 ret = self。oleobj .Invoke(retEntry.dispid,0,invoke_type,1) 所以它已经在 try & except 之下。我不明白为什么它没有捕捉到错误。
我使用 Python 3.8.10 32bit、Pyinstaller 4.3、pywin32 301、OS 64bit、Windows 7
我的用户使用的是 64 位操作系统,Windows 10
