AttributeError: 'module' object as no attribute '_Application'

[亡魂溺海] 提交于 2019-12-11 18:08:59

问题


At end of my program, I am generating word file then converting this file to .pdf file format as the following:

wdFormatPDF = 17
word = comtypes.client.CreateObject('Word.Application')
doc = word.Documents.Open(resultfile)
doc.SaveAs(resultfilepdf, FileFormat=wdFormatPDF)
doc.Close()
word.Quit()

The program run properly but when I converting the

.py to .exe using pyinstaller –onefile option I get the following error when executing the .exe file.

Traceback (most recent call last):
  File "C:\python\tub\test\hc.py", line 344, in <module>
    word = comtypes.client.CreateObject('Word.Application')
  File "C:\Users\LT440\Anaconda2\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
return _manage(obj, clsid, interface=interface)
  File "C:\Users\LT440\Anaconda2\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
  File "C:\Users\LT440\Anaconda2\lib\site-packages\comtypes\client\__init__.py", line 112, in GetBestInterface
interface = getattr(mod, itf_name)
AttributeError: 'module' object has no attribute '_Application'
[4112] Failed to execute script hc

Please advice.


回答1:


I have same。I solved it Clear Gen's cache! I am deleting all the caches in this directory. The conversion is normal! ..\Python3.6\Lib\site-packages\comtypes\gen



来源:https://stackoverflow.com/questions/48986806/attributeerror-module-object-as-no-attribute-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!