0

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.

I_do_python
  • 1,366
  • 4
  • 16
  • 31

1 Answers1

2

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.

I_do_python
  • 1,366
  • 4
  • 16
  • 31
  • 1
    It was including part of lxml, but it missed another part that it needed to include. – Thomas K May 30 '15 at 18:25
  • What I've also noticed is that the docx templates aren't included in the `library.zip` created by cx_freeze. Editing that library post freeze gives me more errors, so I moved the template (which is just a blank docx file) in the working directly and explicitly open it, rather than just `document()`. – I_do_python May 31 '15 at 04:51
  • Hi, i know i'm late, but how did you do that? @I_do_python – aaossa Nov 03 '15 at 15:21
  • Neverming, i solved it copying the docx `document.py` module inside my function (instead of using `Document()` and solved it. Thanks by posting your solution :) – aaossa Nov 03 '15 at 15:42
  • @aaossa: how did you do it? I am struggling with the same problem right now – pawelty Sep 07 '16 at 12:30