py2exe PackageNotFoundError

时间:2015-06-23 15:46:23

标签: python py2exe

我目前正在尝试使用py2exe将Tkinter应用程序打包成.exe文件。包装工作正常,直到一定程度,程序运行。但是,当我调用某个函数时,运行.exe文件会记录以下错误:

,host25

在最初运行py2exe时,我检查了\ docx \文件夹,发现py2exe实际上没有复制到\ templates \文件夹。手动解压缩library.zip后,在正确的位置添加\ templates \文件夹,然后手动重新压缩,但是,我得到相同的错误。

我的setup.py如下:

Exception in Tkinter callback
Traceback (most recent call last):
  File "Tkinter.pyc", line 1532, in __call__
  File "/Users/Gordon/Gordon's Files/AutoFormatter/lib\formatterApp.py", line 58, in go
  File "formatter.pyc", line 72, in take
  File "docx\api.pyc", line 25, in Document
  File "docx\opc\package.pyc", line 116, in open
  File "docx\opc\pkgreader.pyc", line 32, in from_file
  File "docx\opc\phys_pkg.pyc", line 31, in __new__
PackageNotFoundError: Package not found at 'C:\Users\Gordon\Gordon's Files\AutoFormatter\dist\library.zip\docx\templates\default.docx'

我使用Python 2.7.8和py2exe 0.6.9在Windows 7计算机上运行程序。

1 个答案:

答案 0 :(得分:0)

这可能为时已晚,但我也遇到了同样的麻烦。我不知道python-docx是否被编译成单个可执行文件,但我找到了解决方案。

我在使用python2.7进行pyinstaller,基本上是一样的。我希望你冻结到一个目录而不是一个文件。 如果您冻结到一个文件,这将无法运作

下载this here(Mediafire链接)

将其放入

C:\Users\Gordon\Gordon's Files\AutoFormatter\dist\library.zip\docx\templates\default.docx

基本上你的.exe所在的地方。

希望这可以解决问题

基于我在我自己的目录和docx模块中搜索,当您创建文档时:

doc = Document()
doc.save('hello.docx')

它提供了一个模板供您使用,如果您不创建自己的模板,它将使用python-docx本身提供的默认模板。

请不要引用我这个,但我相信python-docx会查看自己的目录,以便在通过python执行时找到default.docx模板。

由于我们编译了脚本,因此路径更改为放置.exe的目录,但是pyinstaller(或者在你的情况下为py2exe)不包含带dist文件夹的模板,这会创建PackageNotFoundError

相关问题