Search code examples
pythontkintercx-freeze

invalid syntax at cx_Freeze executables


I made a tkinter application in windows and now I want to make an executable version of it. multiframe.py contains all the the code of the tkinter application.

But when I try to build it I always get syntax error but I don't get it why. Here is a cmd snapshot. enter image description here

This is how my setup.py looks like:

    import cx_Freeze

    base = None

    if sys.platform == 'Win32':
            base = "Win32GUI"

    executables = [cx_Freeze.Executable("frame.py"), base=base, icon='ds.ico']

    cx_Freeze.setup(
            name="cuQ",
            options = {"build_exe": {"packages":["tkinter"], include_files=["ds.ico"]},
            version= "0.01",
            description = "dasdasd",
            executables = executables
            )

Solution

  • base and icon are options of cx_Freeze.Executable in your code they're not being passed to it. They need to be in () just like "frame.py" is so use:

    executables = cx_Freeze.Executable("frame.py", base=base, icon='ds.ico')
    

    In cx_Freeze.setup(options = ... you're first adding a dictionary key "packages" as part of the value for the dictionary key "build_exe" but then suddenly you're trying to add a list include_files instead of a key while still inside the dictionary that is the part of the value alongside "packages" to "build_exe" key. It's hard to describe. Anyway.

    Your whole code should look like:

    import cx_Freeze, sys
    
    base = None
    
    if sys.platform == 'Win32':
        base = "Win32GUI"
    
    executables = cx_Freeze.Executable("frame.py", base=base, icon='ds.ico')
    
    cx_Freeze.setup(
            name="cYou",
            options = {"build_exe": {"packages":["tkinter"], "include_files":["ds.ico"]}},
            version= "0.01",
            description = "dasdasd",
            executables = executables
            )
    

    Below is what I use for tkinter. I just put my tkinter script something.py next to this script. Then I just respond to it something. Some modifications may need to be done in order to include icon files and such:

    from cx_Freeze import setup, Executable
    import sys, os
    
    fileName = input("What's the name of the py file to be converted to .exe?\n")
    sys.argv.append('build')
    
    os.environ['TCL_LIBRARY'] = r'C:\Users\username\AppData\Local\Programs\Python\Python36\tcl\tcl8.6'
    os.environ['TK_LIBRARY'] = r'C:\Users\username\AppData\Local\Programs\Python\Python36\tcl\tk8.6'
    
    base = None
    if (sys.platform == "win32"):
        base = "Win32GUI"    # Tells the build script to hide the console.
    elif (sys.platform == "win64"):
        base = "Win64GUI"    # Tells the build script to hide the console.
    
    
    
    setup(
        name='KutsalAklinNerde?',
        version='0.1',              #Further information about its version
        description='Parse stuff',  #It's description
        executables=[Executable(fileName + ".py", base=base)])