creating .exe file with cx_freeze for a tkinter interface

16,057

I'd make this a comment but I don't have the reputation yet...

Any warnings/errors from the compilation output/logs?

Anything when you run the executable at the command prompt?

Does your executable need libraries that cx_freeze isn't finding?

You'll likely need to specify additional options like included libraries... Tweaking the example in the cx_freeze documentation you can specify to include TKinter:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"includes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name = "simple_Tkinter",
    version = "0.1",
    description = "Sample cx_Freeze Tkinter script",
    options = {"build_exe": build_exe_options},
    executables = [Executable("the timer.py", base = base)])

setup(  name = "guifoo",
        version = "0.1",
        description = "My GUI application!",
        options = {"build_exe": build_exe_options},
        executables = [Executable("guifoo.py", base=base)])

I know I've had lots of fun issues getting py2exe to work with PySide/PyQt4, matplotlib, numpy, etc. Some modules, like matplotlib, even provide a method to list all the data files necessary to build/distribute an application (matplotlib.get_py2exe_datafiles()). Solutions for Enthought's TraitsUI utilize glob to grab the directories of files needed. My point is, because module imports can be dynamic, messy, or black-magical in some libraries, many of the build utilities are unable to locate all the required resources. Also, once your executable is working, if you find stuff in the distribution you know your application won't need, you might can exclude it with additional options, which helps trim bloat from your distribution. Hopefully TKinter won't be too hard to get working - it appears others on StackOverflow were successful.

I'm sorry I don't have a rock solid solution, but I'm trying to help where I can! Good luck!

Share:
16,057
rodrigocf
Author by

rodrigocf

Updated on June 30, 2022

Comments

  • rodrigocf
    rodrigocf almost 2 years

    I have searched for this answer all around the place, but i can't find an answer. I have a python script (3.3) that has an interface with tkinter. I used cx_freeze to create an executable out of it, got a build folder with some files and folders in it. I double clicked on the .exe file and nothing happened. I'm using the following setup:

    import sys
    
    from cx_Freeze import setup, Executable
    
    
    
    base = None
    if sys.platform == "win32":
        base = "Win32GUI"
    
    setup(
            name = "simple_Tkinter",
            version = "0.1",
            description = "Sample cx_Freeze Tkinter script",
            executables = [Executable("the timer.py", base = base)])
    

    If i just open my code and run it the interface works perfectly. I do not get any error messages while doing the build (at least none that i can see... btw, how do i verify this?). Any ideas on what the problem could be? or any other alternative modules?

    Thanks!! :)

  • rodrigocf
    rodrigocf about 10 years
    Thank you vey much for your answer. I have found the problem and I feel a little dumb... I didn't add the root.mainloop() at the end... It was a rookie mistake, but I will definitely keep in mind the build_exe_options part! Thanks again!! :)