Search code examples
pythonpython-3.xcx-freezepython-docx

Cx_freeze exe failing to completely import docx


I have a pretty hefty python script that I'm trying to cx_freeze, however when I run the executable file I keep getting the same error and it appears to be related to the docx module.

I'm using Python 3.3.5 with docx 0.7.6-py33 on a Windows 8.1 machine.

This is my setup script.

from cx_Freeze import setup, Executable

includefiles = ['logo.ico','db.db','dbloc.bin']
includes = []
excludes = []
packages = ['tkinter','docx','sys', 'sqlite3', 'os', 'hashlib', 'random', 'uuid', 'base64', 'tempfile', 'win32api',
            'winreg', 'ntplib', 'winsound', 'time', 'csv', 'webbrowser', 'inspect','datetime', 'decimal', 'ctypes',
            'win32com.client','operator']

exe = Executable(
# what to build
   script = "NEPOS.py",
   initScript = None,
   base = 'Win32GUI',
   targetName = "Nepos.exe",
   copyDependentFiles = True,
   compress = True,
   appendScriptToExe = True,
   appendScriptToLibrary = True,
   icon = 'Icon.ico'
)

setup(
    name = "MyProgram",
    version = "1.0.0",
    description = 'Description',
    author = "Joe Bloggs",
    author_email = "123@gmail.com",
    options = {"build_exe": {"excludes":excludes,"packages":packages,
      "include_files":includefiles}},
    executables = [exe]
)

This is the error I'm getting.

enter image description here

It looks like it is having trouble finding methods that belong to docx, but my source code calls import docx and it is listed as a dependent module in the setup file so I'm not sure why they aren't being included.


Solution

  • After a LOT of messing about I've finally cracked this. The docx module is dependent on lxml. Even though the raw .py file runs perfectly fine with just docx imported, when cx_freezing you need to explicitly state the dependency by adding lxml to the packages.