问题描述
我正在尝试按照本教程创建一个可执行文件
I'm trying to create an executable following this tutorial
https://github.com/anthony-tuininga/cx_Freeze/tree/master/cx_Freeze/samples/Tkinter
经过一些调整后,我能够编译该项目,但是当我单击 .exe 时,鼠标加载动画会触发,但没有加载任何内容.这个问题以前有人问过,但从未得到解决.
After some tweaking I'm able to compile the project but when i click the .exe the mouse loading animation fires but nothing ever loads. This questions has been asked previously but was never resolved.
当您的 .exe 在 cx_freeze 后不起作用时,从哪里开始查看代码?
我的应用文件
from tkinter import *
from tkinter import messagebox
root = Tk()
root.title('Button')
print("something")
new = messagebox.showinfo("Title", "A tk messagebox")
root.mainloop()
我的 setup.py
my setup.py
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [
Executable('SimpleTkApp.py', base=base)
]
setup(name='simple_Tkinter',
version='0.1',
description='Sample cx_Freeze Tkinter script',
executables= [Executable("SimpleTkApp.py", base=base)])
我也手动添加了 TCL/TK 库
Also I have been manually adding the TCL/TK libraries
set TK_LIBRARY=C:... k8.6 etc
我的配置:python 3.7,cx_Freeze 5.1.1
My configuration: python 3.7, cx_Freeze 5.1.1
任何帮助将不胜感激,我什至不知道从哪里开始.
Any help would be greatly appreciated, I don't even know where to start on this one.
推荐答案
尝试修改你的setup.py
如下:
import sys
from cx_Freeze import setup, Executable
import os
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')
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'))]
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [Executable('SimpleTkApp.py', base=base)]
setup(name='simple_Tkinter',
version='0.1',
description='Sample cx_Freeze Tkinter script',
options={'build_exe': {'include_files': include_files}},
executables=executables)
这应该适用于 cx_Freeze
版本 5.1.1(当前版本).在此版本中,包含的模块位于构建目录的子目录 lib
中.如果你使用5.0.1或更早的版本,设置
This should work for cx_Freeze
version 5.1.1 (the current version). In this version, the included modules are in a subdirectory lib
of the build directory. If you use 5.0.1 or an earlier version, set
include_files = [os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')]
相反.
另请参阅获取导入错误:DLL 加载失败:找不到指定的模块";当使用 cx_Freeze 时,即使添加了 tcl86t.dll 和 tk86t.dll 和 使用 cx_Freeze for windows 构建的 python tkinter exe 也不会显示图形界面
另一个问题是 cx_Freeze
在 python 3.7 中存在一个尚未纠正的错误.请参阅 Cx_freeze 使 Python3.7.0 崩溃.您可以在那里找到指向您应该手动应用的错误修复的链接(根据 OP 这解决了问题,请参阅评论).
A further problem is that cx_Freeze
has a bug with python 3.7 which is not yet corrected. See Cx_freeze crashing Python3.7.0 . You can find there a link to a bug fix which you should apply manually (according to the OP this solved the problem, see comments).
这篇关于tkinter 程序使用 cx_Freeze 编译但程序不会启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!