py2exe&win32 OLEObject错误(py2exe & win32 OLEObject error)

我试图用py2exe将我的程序编译成exe文件。 不幸的是,当我使用win32com从Excel复制图表并使用(Shapes.PasteSpecial(ppPasteOLEObject)将它们嵌入到PowerPoint中时,我经常会遇到以下错误:

File "win32com\client\__init__.pyc", line 170, in __getattr__ AttributeError: ppPasteOLEObject`.

谷歌搜索没有真正帮助。 当我在python中运行它时,该脚本完美工作,所以我知道问题出在win32com上。 使用makepy.py来包含typelib也没有帮助,但也许我的setup.py是错误的。 所以这里是:

import sys from distutils.core import setup import py2exe from glob import glob from os.path import normpath import matplotlib sys.setrecursionlimit(5000) data_files=[("Microsoft.VC90.CRT",glob(normpath( r'C:/Program Files/Microsoft Visual Studio 9.0/VC/redist/x86/Microsoft.VC90.CRT/*.*'))), ("images",glob(normpath("images/*.PNG"))), ("ppttemplate",glob(normpath("ppttemplate/*.pptx")), (".",normpath("C:/windows/system32/ole32.dll")), (".",normpath("C:/Anaconda2/envs/py27/Library/bin/MSVCP90.dll"))) ] data_files.extend(matplotlib.get_py2exe_datafiles()) setup( data_files=data_files, console=['Main.py'], options={"py2exe":{"includes":["lxml.etree","lxml._elementpath","gzip", "sip","PyQt4.QtGui","PyQt4.QtCore","matplotlib"], "excludes":["Tkinter"], "typelibs":[('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 8), ('{00020430-0000-0000-C000-000000000046}', 0, 2, 0)] } } )

在此先感谢您的帮助!

I have tried to compile my program into an exe with py2exe. Unfortunately, as I am using win32com to copy charts from Excel and embed them into PowerPoint using (Shapes.PasteSpecial(ppPasteOLEObject), I constantly get this error:

File "win32com\client\__init__.pyc", line 170, in __getattr__ AttributeError: ppPasteOLEObject`.

Googling hasn't really helped. The script works perfectly when I run it in python, so I know the problem is with win32com. Using makepy.py to include typelibs also didn't help, but maybe my setup.pyis just wrong. So here it is:

import sys from distutils.core import setup import py2exe from glob import glob from os.path import normpath import matplotlib sys.setrecursionlimit(5000) data_files=[("Microsoft.VC90.CRT",glob(normpath( r'C:/Program Files/Microsoft Visual Studio 9.0/VC/redist/x86/Microsoft.VC90.CRT/*.*'))), ("images",glob(normpath("images/*.PNG"))), ("ppttemplate",glob(normpath("ppttemplate/*.pptx")), (".",normpath("C:/windows/system32/ole32.dll")), (".",normpath("C:/Anaconda2/envs/py27/Library/bin/MSVCP90.dll"))) ] data_files.extend(matplotlib.get_py2exe_datafiles()) setup( data_files=data_files, console=['Main.py'], options={"py2exe":{"includes":["lxml.etree","lxml._elementpath","gzip", "sip","PyQt4.QtGui","PyQt4.QtCore","matplotlib"], "excludes":["Tkinter"], "typelibs":[('{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}', 0, 2, 8), ('{00020430-0000-0000-C000-000000000046}', 0, 2, 0)] } } )

Thanks in advance for your help!

最满意答案

得到它了! 只需要包含相关的dll并设置skip_archive=True ...(我包含了py2exe所抱怨的所有内容)。

通过增加:

sys.path.append("C:\\Program Files\\Microsoft VisualStudio9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT") sys.path.append("C:\\windows\\system32")

在data_files行之前,将所有system32添加到data_files并在py2exe:添加skip_archive=True py2exe:它工作了! 希望它能在不同的计算机上运行......

我使用的指南是在[py2exe]( http://www.py2exe.org/index.cgi/IncludingTypelibs )的网站上!

Got it! One just needs to inlude the relevant dlls and set skip_archive=True... (I included everything that py2exe was complaining about).

By adding:

sys.path.append("C:\\Program Files\\Microsoft VisualStudio9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT") sys.path.append("C:\\windows\\system32")

before the data_files line and adding all the system32 to data_files and adding skip_archive=True inside py2exe: it worked! Hopefully it functions on different computers as well...

The guide I used was on the website of [py2exe] (http://www.py2exe.org/index.cgi/IncludingTypelibs)!

更多推荐