0

My program is supposed to open a docx file 'Core.docx' with python-docx and does it just fine until I make an executable out of it with pyinstaller. I got the same error doing this on Windows 10 but was able to fix it by manually copying 'Core.docx' into the dist folder. On Mac, it doesn't solve it.

Error:

Traceback (most recent call last):
  File "script.py", line 13, in <module>
  File "docx/api.py", line 25, in Document
  File "docx/opc/package.py", line 128, in open
  File "docx/opc/pkgreader.py", line 32, in from_file
  File "docx/opc/phys_pkg.py", line 30, in __new__
docx.opc.exceptions.PackageNotFoundError: Package not found at 'Core.docx'
[7946] Failed to execute script 'script' due to unhandled exception!

I've also tried the function --add-data after reading this exchange:

pyinstaller -F --add-data "Core.docx:Core.docx" script.py

It ran but nothing seems to have actually changed.

Does anyone know of any solutions?

  • You may need to set the current working directory with os.chdir(), to the value of sys._MEIPASS (only if bundled). See this page for sort of what I'm talking about: https://pyinstaller.readthedocs.io/en/stable/runtime-information.html#run-time-information – Starbuck5 Dec 22 '21 at 03:47
  • Thank you, @Starbuck5. The default current directory of the script is indeed somewhere else, so no wonder adding the file to the folder with my exe file didn't work. I was able to add my docx to the bundle and then call it with sys._MEIPASS by following this example code: https://stackoverflow.com/a/51061279/17735259. – pillowedwillow Dec 22 '21 at 19:23

0 Answers0