使用 cx_freeze 为 tkinter 接口创建 .exe 文件 [英] creating .exe file with cx_freeze for a tkinter interface

查看:22
本文介绍了使用 cx_freeze 为 tkinter 接口创建 .exe 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处寻找这个答案,但我找不到答案.我有一个 python 脚本(3.3),它有一个与 tkinter 的接口.我使用 cx_freeze 从中创建了一个可执行文件,得到了一个包含一些文件和文件夹的构建文件夹.我双击了 .exe 文件,什么也没发生.我正在使用以下设置:

I have searched for this answer all around the place, but i can't find an answer. I have a python script (3.3) that has an interface with tkinter. I used cx_freeze to create an executable out of it, got a build folder with some files and folders in it. I double clicked on the .exe file and nothing happened. I'm using the following setup:

import sys

from cx_Freeze import setup, Executable



base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
        name = "simple_Tkinter",
        version = "0.1",
        description = "Sample cx_Freeze Tkinter script",
        executables = [Executable("the timer.py", base = base)])

如果我只是打开我的代码并运行它,界面就完美无缺.在进行构建时我没有收到任何错误消息(至少我看不到任何错误消息......顺便说一句,我如何验证这一点?).关于问题可能是什么的任何想法?或任何其他替代模块?

If i just open my code and run it the interface works perfectly. I do not get any error messages while doing the build (at least none that i can see... btw, how do i verify this?). Any ideas on what the problem could be? or any other alternative modules?

谢谢!!:)

推荐答案

我想把它作为评论,但我还没有声誉...

I'd make this a comment but I don't have the reputation yet...

编译输出/日志中是否有任何警告/错误?

Any warnings/errors from the compilation output/logs?

在命令提示符下运行可执行文件时有什么问题吗?

Anything when you run the executable at the command prompt?

您的可执行文件是否需要 cx_freeze 找不到的库?

Does your executable need libraries that cx_freeze isn't finding?

您可能需要指定其他选项,例如包含的库...调整 cx_freeze 文档 中的示例,您可以指定为包括 TKinter:

You'll likely need to specify additional options like included libraries... Tweaking the example in the cx_freeze documentation you can specify to include TKinter:

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"includes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name = "simple_Tkinter",
    version = "0.1",
    description = "Sample cx_Freeze Tkinter script",
    options = {"build_exe": build_exe_options},
    executables = [Executable("the timer.py", base = base)])

setup(  name = "guifoo",
        version = "0.1",
        description = "My GUI application!",
        options = {"build_exe": build_exe_options},
        executables = [Executable("guifoo.py", base=base)])

我知道我在让 py2exe 与 PySide/PyQt4、matplotlib、numpy 等一起工作时遇到了很多有趣的问题.一些模块,如 matplotlib,甚至提供了一种方法来列出构建/分发所需的所有数据文件应用程序(matplotlib.get_py2exe_datafiles()).Enthought 的 TraitsUI 解决方案利用 glob 来获取所需文件的目录.我的观点是,因为模块导入在某些库中可能是动态的、混乱的或神秘的,许多构建实用程序无法找到所有必需的资源.此外,一旦您的可执行文件运行,如果您在发行版中发现您知道应用程序不需要的内容,您可以使用其他选项将其排除,这有助于减少发行版中的膨胀.希望 TKinter 不会太难开始工作 - StackOverflow 上的其他人似乎成功了.

I know I've had lots of fun issues getting py2exe to work with PySide/PyQt4, matplotlib, numpy, etc. Some modules, like matplotlib, even provide a method to list all the data files necessary to build/distribute an application (matplotlib.get_py2exe_datafiles()). Solutions for Enthought's TraitsUI utilize glob to grab the directories of files needed. My point is, because module imports can be dynamic, messy, or black-magical in some libraries, many of the build utilities are unable to locate all the required resources. Also, once your executable is working, if you find stuff in the distribution you know your application won't need, you might can exclude it with additional options, which helps trim bloat from your distribution. Hopefully TKinter won't be too hard to get working - it appears others on StackOverflow were successful.

很抱歉,我没有可靠的解决方案,但我会尽力提供帮助!祝你好运!

I'm sorry I don't have a rock solid solution, but I'm trying to help where I can! Good luck!

这篇关于使用 cx_freeze 为 tkinter 接口创建 .exe 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆