Search code examples
pythonwindowspython-3.xcompilationcx-freeze

Compile multiple .py files to windows executable (.exe)


I have a relatively small python program that I want to convert to a windows executable. It was originally written with Pycharm and runs normally in it.

It consists of two .py files that I have written and some libraries (all installed from pip).

I am trying to do my job with cx_Freeze but not with much success. My setup.py is this:

from cx_Freeze import setup, Executable
import os.path

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6') 
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

setup(name="MFS-printer",
      version='1.0.0',
      description='A parser for the log file from the terminal exit of the mfs system',
      options={"build_exe": {"packages": ["file_read_backwards", "Pil", "watchdog", "win32print", "win32ui", "tkinter", "log_parser"],
                             "include_files": ["Roboto-Bold.ttf", "mfs_robot(2).png", os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'), os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),]
                             }
                },
      executables = [Executable("main.py"), Executable("log_parser.py")], requires=['watchdog']
      )

After running python setup.py build to create the windows application no errors exist but when I try to run the application it crashes at start with this error:

this is after I double click on the executable

My imports from those two files (main.py and log_parser.py) are the folowing:

main.py:

import os,time
import datetime
import log_parser

import win32print
from tkinter import filedialog
from tkinter import *

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from pathlib import Path

log_parser.py

import os

import win32print
import win32ui

from file_read_backwards import FileReadBackwards
from PIL import Image, ImageDraw, ImageFont, ImageWin

There is probably something wrong with the setup.py but I can't find what. Any help would be appreciated.


Solution

  • It seems that for now cx_Freeze does not really support Python3.7 for Windows 64bit (until this date). This it the Github issue that refers to it. I hope by the time someone else searches for it, it will be fixed!

    https://github.com/anthony-tuininga/cx_Freeze/issues/399