我开发了一个 tkinter gui 应用程序并使用 cx_Freeze 将其转换为 exe。
exe 文件工作正常。但几天后,当我尝试打开它时,它正在启动应用程序并立即关闭。我还尝试创建 bat 文件以查看是否引发任何错误。但没有出现错误。 毕竟,我尝试使用相同的安装文件再次生成新的版本。它运行良好,并且应用程序可以正常打开。但不知道旧的有什么问题。
如果有人看到这种奇怪的行为,请帮助我。
作为引用,我复制了下面的设置文件:
import os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = 'C:/Program Files/Python3.6/tcl/tcl8.6'
os.environ['TK_LIBRARY'] = 'C:/Program Files/Python3.6/tcl/tk8.6'
buildOptions = dict(
packages = ["pandas","tkinter","numpy","pandatables","Images"],
excludes = [],
include_files=['C:/Program Files/Python3.6/DLLs/tcl86t.dll', 'C:/Program Files/Python3.6/DLLs/tk86t.dll']
)
import sys
base = 'Win32GUI' if sys.platform=='win32' else None
executables = [
Executable('DE.py', base=base)
]
setup(name='DE Validator',
version = '1.0',
description = '',
options = dict(build_exe = buildOptions),
executables = executables)'
最佳答案
对于 cx_Freeze
版本 5.1.1,TCL/TK DLL 需要包含在构建目录的 lib
子目录中。您可以通过将元组(源,目标)
传递到include_files
列表选项的相应条目来做到这一点。
此外,动态查找 TCL/TK DLL 的位置会更安全。
尝试按如下方式修改您的设置脚本:
import sys
PYTHON_INSTALL_DIR = os.path.dirname(sys.executable)
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')
buildOptions = dict(
packages = ["pandas","tkinter","numpy","pandatables","Images"],
excludes = [],
include_files=[(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join('lib', 'tk86t.dll')),
(os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll'),
os.path.join('lib', 'tcl86t.dll'))]
)
关于python - cx_Freeze Exe 应用程序一打开就关闭,没有任何错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54329626/