Search code examples
pythonpython-3.xpyinstallerexepython-docx

Python-docx and Pyinstaller not working together


Good evening all, I've recently completed an app I was working on in python, and now that I am packaging it using Pyinstaller, but after packaging it, I tried to use the app for its purpose and generate some reports, however, it suddenly can't in the exe file but works in the text editor and is not showing any errors for some odd reason, I've tried this thread to no avail and I am now lost.

.spec file:

# -*- mode: python ; coding: utf-8 -*-
import sys
from os import path
site_packages = next(p for p in sys.path if 'site-packages' in p)
from kivy_deps import sdl2, glew

block_cipher = None


a = Analysis(['C:\\Users\\Admin\\Newark\\newarkp.py'],
             pathex=['C:\\Users\\Admin\\Newark'],
             binaries=[],
             datas=[(path.join(site_packages,"docx","templates"), 
"docx/templates")],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='Newark',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True , icon='C:\\Users\\Admin\\Newark\\logo_icon.ico')
coll = COLLECT(exe, Tree('C:\\Users\\Admin\\Newark\\'),
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
               strip=False,
               name='Newark',
               upx=True,)

Solution

  • I figured it out for anyone seeing this, some of my files got misplaced during the packaging so when I tried to use them, they were using another useless file and nothing was happening as a result.

    Always check that your files are in the correct directories after packaging