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

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

问题描述

我在各处搜索了该答案,但是找不到答案。我有一个与tkinter接口的python脚本(3.3)。我使用cx_freeze从中创建可执行文件,并获得了一个包含一些文件和文件夹的build文件夹。我双击.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天全站免登陆