cx_Freeze 个可执行文件的语法无效
invalid syntax at cx_Freeze executables
我在 windows 中制作了一个 tkinter 应用程序,现在我想制作它的可执行版本。 multiframe.py 包含 tkinter 应用程序的所有代码。
但是当我尝试构建它时,我总是遇到语法错误,但我不明白为什么。这是一个 cmd 快照。
这是我的 setup.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
)
base
和 icon
在您的代码中是 cx_Freeze.Executable
的 options
,它们没有被传递给它。他们需要在 ()
中,就像 "frame.py"
一样,所以使用:
executables = cx_Freeze.Executable("frame.py", base=base, icon='ds.ico')
在 cx_Freeze.setup(options = ...
中,您首先添加字典键 "packages"
作为字典键 "build_exe"
值的一部分,但突然您尝试添加列表 include_files
而不是键,同时仍在字典中,它是 "packages"
到 "build_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)])
我在 windows 中制作了一个 tkinter 应用程序,现在我想制作它的可执行版本。 multiframe.py 包含 tkinter 应用程序的所有代码。
但是当我尝试构建它时,我总是遇到语法错误,但我不明白为什么。这是一个 cmd 快照。
这是我的 setup.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
)
base
和 icon
在您的代码中是 cx_Freeze.Executable
的 options
,它们没有被传递给它。他们需要在 ()
中,就像 "frame.py"
一样,所以使用:
executables = cx_Freeze.Executable("frame.py", base=base, icon='ds.ico')
在 cx_Freeze.setup(options = ...
中,您首先添加字典键 "packages"
作为字典键 "build_exe"
值的一部分,但突然您尝试添加列表 include_files
而不是键,同时仍在字典中,它是 "packages"
到 "build_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)])