TO BE MORE SPECIFIC: This program is not running AT ALL, only opening the command prompt and suddenly shutting down... Heres my setup.py file... I imported os and added the links to tcl and tk to prevent another issue for occurring. After solving that issue and now I am able to successfully build an .exe from my raw python code but, when opening the freshly created .exe file... All it will do it open a command prompt screen for mere milliseconds and close once again. I am assuming there was some build error possibly with tk.mainLoop() or tkinter in general? I am also importing the math module and a couple of other tkinter items such as tkinter.font and tkinter.messagebox. Would really appreciate the help, I've been having a TON of issues with cx_Freeze and python-to-executable programs/modules in general...
import os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = 'c:/python36-32/tcl/tcl8.6'
os.environ['TK_LIBRARY'] = 'c:/python36-32/tcl/tk8.6'
base = None
executables = [Executable("formulas_tkinter_replace2.py", base=base, icon="pi-outline-128.ico")]
packages = ["tkinter", "math"]
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "Formula",
version = "1.0",
description = 'Mathematics made easy...',
executables = executables
)
Basically the Tk and Tcl DLL are both missing. There are two ways you correct this.
1) This is more of a hack and only sometimes works but in this case it should:
Copy tcl86t.dll
and tk86t.dll
from your Python installation to the location of your exe. These can be found at Python36-32/DLLs
. That's it.
2) The 'proper' way to do it would be to do something like this: Put this before executable:
files = {"include_files": ["C:/File_to_python/Python36-32/DLLs/tcl86t.dll", "C:/File_to_python/Python36-32/DLLs/tk86t.dll"]}
and
options = {
'build_exe': {
'packages':packages,
'build_exe':files
},
}
in the place of what you had before.
EDIT: Right. This script should work. I completely rewrote the setup script you provided however essentially what you did is correct however the error appeared because the file tcl8.6
was not found and you also forgot to use the include_files
function. This can be done manually though.
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "FilePathToPython/Python36-32/tcl/tcl8.6"
os.environ['TK_LIBRARY'] = "FilePathToPython/Python36-32/tcl/tk8.6"
files = {"include_files":["FilePathToPython/Python36-32/DLLs/tcl86t.dll", "FilePathToPython/Python36-32/DLLs/tk86t.dll", "pi-outline-128.ico"], "packages": ["tkinter"]}
base = None
setup( name = "Name of exe",
version = "0.0",
author = "Reader",
description = "compile with setup.py build",
options = {"build_exe": files},
executables = [Executable("formulas_tkinter_replace2.py", icon="pi-outline-128.ico", base=base)])
Just replace what you need to.
As I already said. You can hide the console completely by using base = 'Win32GUI'