AttributeError: 'module' 对象没有属性 '_Application' [英] AttributeError: 'module' object as no attribute '_Application'

查看:234
本文介绍了AttributeError: 'module' 对象没有属性 '_Application'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序结束时,我正在生成 word 文件,然后将此文件转换为 .pdf 文件格式,如下所示:

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 到 .exe 使用 pyinstaller –onefile 选项我在执行 .exe 文件时收到以下错误.

.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

请指教.

推荐答案

我也有.我解决了清除Gen的缓存!我正在删除此目录中的所有缓存.转换正常!..\Python3.6\Lib\site-packages\comtypes\gen

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

这篇关于AttributeError: 'module' 对象没有属性 '_Application'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆