cx_Freeze Exe应用程序一打开就关闭,没有任何错误

时间:2019-01-23 14:36:21

标签: python cx-freeze

我已经开发了一个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)'

1 个答案:

答案 0 :(得分:0)

对于cx_Freeze版本5.1.1,TCL / TK DLL必须包含在构建目录的lib子目录中。您可以通过将元组(source, destination)传递到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'))]
)