py2exe PackageNotFoundError

652 Views Asked by At

I'm currently trying to package a Tkinter app into a .exe file using py2exe. The packaging works fine, and up until a point, the program functions. When I call a certain function, though, running the .exe file logs the following error:

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'

Upon originally running py2exe, I checked the \docx\ folder and found that py2exe hadn't actually copied over the \templates\ folder. After manually unzipping the library.zip, adding in the \templates\ folder in the right place, and then manually re-zipping, however, I get the same error.

My setup.py is as follows:

from distutils.core import setup
import py2exe

setup(
    windows=[{'script': 'AutoFormatter.py'}],
    options={
        'py2exe': 
        {
            'includes': ['lxml.etree', 'lxml._elementpath', 'gzip', 'docx'],
        }
    }
)

I'm running the program on a Windows 7 computer using Python 2.7.8 and py2exe 0.6.9.

1

There are 1 best solutions below

1
On

This might be too late but I have been having the same troubles as well. I don't know if python-docx was made to be compiled into a single executable yet, none the less I have found solution.

I am on pyinstaller with python2.7, essentially the same thing. I hope that you are freezing into one directory rather than one file. This won't work if you're freezing to one file

Download this here(Mediafire link)

Place it in

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

basically wherever your .exe is in.

Hopefully that does the trick

Based off of me scouring through my own directories and the docx module, when you create a document:

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

It pulls a template for you to use, if you do not create your own, it will use the default template offered by python-docx itself.

Don't quote me on this, but I believe python-docx looks through its own directories to find the default.docx template when executing it through python.

Since we compiled the script, the path changed to the directory in which the .exe is placed, however pyinstaller (or in your case py2exe) does not include the template with the dist folder, and this creates the PackageNotFoundError