代码之家  ›  专栏  ›  技术社区  ›  Marci

cx_Freeze可执行文件处的语法无效

  •  0
  • Marci  · 技术社区  · 7 年前

    我在windows中制作了一个tkinter应用程序,现在我想制作一个可执行版本。多帧。py包含tkinter应用程序的所有代码。

    但当我试图构建它时,我总是会遇到语法错误,但我不明白为什么。这是cmd快照。 enter image description here

    这就是我的设置。py看起来像:

        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
                )
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Nae    7 年前

    base icon options 属于 cx_Freeze.Executable 在你的代码中,它们没有被传递给它。他们需要加入 () 就像 "frame.py" 是否如此使用:

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

    在里面 cx_Freeze.setup(options = ... 您首先添加了一个字典键 "packages" 作为字典键值的一部分 "build_exe" 但是突然你想要添加一个列表 include_files 而不是仍在字典中的键,它是值的一部分 “包” “build\u exe” 钥匙这很难描述。无论如何

    您的整个代码应该如下所示:

    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
            )
    

    下面是我对tkinter的使用。我只是把我的tkinter脚本 something.py 在此脚本旁边。然后我就回应它 something . 为了包含图标文件,可能需要进行一些修改,例如:

    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)])