Skip to content

Instantly share code, notes, and snippets.

@MattWoodhead
Created June 10, 2017 09:30
Show Gist options
  • Save MattWoodhead/a023ec68cc6834f0aa5ab1f5089336a0 to your computer and use it in GitHub Desktop.
Save MattWoodhead/a023ec68cc6834f0aa5ab1f5089336a0 to your computer and use it in GitHub Desktop.
A cx_freeze setup script that works for executables for python 3.5+ based apps that use the tkinter graphics framework.
"""
A cx_freeze setup script that works for executables for python 3.5+ based
apps that use the tkinter graphics framework.
i.e. fixes the "KeyError: 'TCL_Library'" error
"""
import os
import sys
from cx_Freeze import setup, Executable
# set location tkinter path variables using os
PY_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ["TCL_LIBRARY"] = os.path.join(PY_INSTALL_DIR, "tcl", "tcl8.6")
os.environ["TK_LIBRARY"] = os.path.join(PY_INSTALL_DIR, "tcl", "tk8.6")
# dll files required for tkinter apps
TK86TDLL = os.path.join(PY_INSTALL_DIR, "DLLs", "tk86t.dll")
TCL86TDLL = os.path.join(PY_INSTALL_DIR, "DLLs", "tcl86t.dll")
# GUI applications require a different base on Windows
# (the default is for creation of a console application)
BASE = None
if sys.platform == "win32":
BASE = "Win32GUI"
# Dependencies should be automatically detected, but may need specifying below
OPTIONS = {"build_exe": {"include_files": [TK86TDLL, TCL86TDLL], # tkinter
"packages": ["tkinter"], # Dependancies here
"excludes": [None], # Excludes here
}}
setup(name="test",
version="0.1",
description="My GUI application!",
options=OPTIONS,
executables=[Executable("test.py", base=BASE)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment