我正在尝试使用cx_freeze库从我的python脚本构建一个exe文件。这是我的代码:
super(Person, self).__init__()
这是我的设置代码:
import easygui
easygui.ynbox('Shall I continue?', 'Title', ('Yes', 'No'))
然后我收到此错误:
import cx_Freeze
import sys
import matplotlib
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("tkinterVid28.py", base=base, icon="clienticon.ico")]
cx_Freeze.setup(
name = "SeaofBTC-Client",
options = {"build_exe": {"packages":["easygui","matplotlib"]}},
version = "0.01",
description = "Sea of BTC trading application",
executables = executables
)
答案 0 :(得分:1)
Easygui使用了一些Tkinter,因此在编译时你必须包含Tkinter库。
这应该是使用include_files
争论
将以下参数添加到脚本中:
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR,'tcl','tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path to Python>/Python36-32/DLLs/tk86t.dll"], , "clienticon.ico" ], "packages": ["easygui","matplotlib"]}
下一次改变:
options = {"build_exe": {"packages":["easygui","matplotlib"]}},
为:
options = {"build_exe": files},
一切都应该有效。您的脚本现在应该如下所示:
import cx_Freeze
import sys
import matplotlib
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR,'tcl','tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
files = {"include_files": ["<Path to Python>/Python36-32/DLLs/tcl86t.dll", "<Path to Python>/Python36-32/DLLs/tk86t.dll"], "packages": ["tkinter", "easygui","matplotlib"]}
base = None
if sys.platform == 'win32':
base = "Win32GUI"
executables = [cx_Freeze.Executable("tkinterVid28.py", base=base,
icon="clienticon.ico")]
cx_Freeze.setup(
name = "SeaofBTC-Client",
options = {"build_exe": files},
version = "0.01",
description = "Sea of BTC trading application",
executables = executables
)
您的脚本中还有另一个错误。因为您没有使用include_files
参数来包含您要使用的图标。它不会出现在可执行文件图标或输出中(如果您在tkinterVid28.py文件中使用它),这将产生错误。
哦,除非你有理由这样做,否则我看不出你为什么要导入matplotlib。 Cx_Freeze检测您尝试转换为可执行文件的脚本中的导入,而不是安装脚本本身,但最好将它们列在包中。
我希望这能解决你的问题