2

我正在开发一个使用模块“pptx”(编辑和操作 powerpoint)的 Python 程序。该程序在解释器中没有问题,但是一旦我将它作为 .exe 文件(使用 cx_freeze 或 py2exe 构建)启动,当我单击主按钮时,我会收到以下错误消息:

Exception in Tkinter callback
Traceback (most recent call last):
File "Tkinter.pyc", line 1470, in __call__
File "pptx_02.py", line 187, in ButtonErstellen
File "pptx\api.pyc", line 29, in __init__
File "pptx\presentation.pyc", line 87, in __init__
File "pptx\presentation.pyc", line 170, in __open
File "pptx\packaging.pyc", line 88, in open
File "pptx\packaging.pyc", line 671, in __new__
PackageNotFoundError: Package not found at 'C:\Users\Moi\Programmation\Python\build\exe.win32-2.7\library.zip\pptx\templates\default.pptx' 

问题是文件“default.pptx”实际上存在于这个地址。

在查看“pptx”的功能时,我可能对这个问题的原因有所了解(但不知道解决方案)。对于最后一个错误:文件“pptx\packaging.pyc”,第 671 行,在new
中是以下代码:

class FileSystem(object):
    """
    Factory for filesystem interface instances.

    A FileSystem object provides access to on-disk package items via their URI
    (e.g. ``/_rels/.rels`` or ``/ppt/presentation.xml``). This allows parts to
    be accessed directly by part name, which for a part is identical to its
    item URI. The complexities of translating URIs into file paths or zip item
    names, and file and zip file access specifics are all hidden by the
    filesystem class. |FileSystem| acts as the Factory, returning the
    appropriate concrete filesystem class depending on what it finds at *path*.
    """
    def __new__(cls, file):
        # if *file* is a string, treat it as a path
        if isinstance(file, basestring):
            path = file
            if is_zipfile(path):
                fs = ZipFileSystem(path)
            elif os.path.isdir(path):
                fs = DirectoryFileSystem(path)
            else:
                raise PackageNotFoundError("Package not found at '%s'" % path)
        else:
            fs = ZipFileSystem(file)
        return fs

问题可能是最终文件 (default.pptx) 不是 zip,而是在 zip 中。但我不知道如何解决它,或者它是否真的是问题所在。

如果有人作为一个想法......

谢谢 !

4

0 回答 0