带有 Tkinter 的 Py2exe [英] Py2exe with Tkinter

查看:57
本文介绍了带有 Tkinter 的 Py2exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 py2exe 将基本的 tkinter GUI 程序转换为 .exe.但是,我在使用以下转换脚本时遇到了错误.

# C:\Python26\test_hello_con.py py2exe从 distutils.core 导入设置导入py2exe设置(windows=[r'C:\Python26\py2exe_test_tk.py'])

C:\Python26\py2exe_test_tk.py 如下代码

将 Tkinter 导入为 tk根 = tk.Tk()root.title("测试")label1 = tk.Label(root,text="Hello!",font=('arial', 10, 'bold'), bg='lightblue')label1.pack(ipadx=100, ipady=100)root.mainloop()

这是我尝试运行新创建的 .exe 时遇到的错误

回溯(最近一次调用最后一次):文件py2exe_test_tk.py",第 4 行,在 <module> 中文件Tkinter.pyc",第 1643 行,在 __init__ 中_tkinter.TclError:在以下目录中找不到可用的 init.tcl:{C:/Users/My_Name/lib/tcl8.5} {C:/Users/My_Name/lib/tcl8.5} C:/Users/lib/tcl8.5 {C:/Users/My_Name/library} C:/Users/library C:/Users/tcl8.5.8/library C:/tcl8.5.8/library这可能意味着 Tcl 没有正确安装.

我很确定是我的转换脚本中的某些内容给我带来了问题.我遗漏了什么?或者有人有一个例子来说明 tkinter GUI 程序的转换脚本是什么样的?也可以将输出的 .exe 文件转移到我的桌面上吗?

错误报告说我从 {C:/Users/My_name/lib/tcl8.5} 中丢失了 init.tcl.所以我创建了那个目录并将 init.tcl 的副本放在那里.现在,当我尝试运行 .exe 时,它​​指出我的计算机中缺少 MSVCR90.dll,并且需要运行我的程序.

这也是 Windows 7 上的 python 2.6.5.

解决方案

对于你最初的问题,我不能说究竟是什么问题,但通常它有助于反复试验猜测丢失的文件和目录.如果您知道自己缺少什么,请将它们添加到您的 packages(对于 Python 模块)或 data_files(对于其他文件).

第二个问题是某些 c 模块(和 python 本身)使用 MS Visual Studio 构建的结果,因此依赖于 MS Visual C++ 9.0 (2008) 运行时.您可以通过以下任一方式解决此问题:

  • 拥有 Visual Studio 的副本(Express Edition 不算在内),以便您可以重新分发 MSVCR 依赖项(在您禁止用户重新生成依赖部分等的情况下)

  • 将您的用户指向 Microsoft 的 MS Visual C++ 2008 Redistributable 包.

I'm trying to convert a basic tkinter GUI program to an .exe using py2exe. However I've run into an error using the following conversion script.

# C:\Python26\test_hello_con.py py2exe

from distutils.core import setup
import py2exe

setup(windows=[r'C:\Python26\py2exe_test_tk.py'])

C:\Python26\py2exe_test_tk.py is the following code

import Tkinter as tk

root = tk.Tk()
root.title("Test")


label1 = tk.Label(root,text="Hello!",font=('arial', 10, 'bold'), bg='lightblue')
label1.pack(ipadx=100, ipady=100)


root.mainloop()

This is the error I get when I try to run the newly created .exe

Traceback (most recent call last):
  File "py2exe_test_tk.py", line 4, in <module>
  File "Tkinter.pyc", line 1643, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories: 
    {C:/Users/My_Name/lib/tcl8.5} {C:/Users/My_Name/lib/tcl8.5} C:/Users/lib/tcl8.5 {C:/Users/My_Name/library} C:/Users/library C:/Users/tcl8.5.8/library C:/tcl8.5.8/library



This probably means that Tcl wasn't installed properly.

I'm pretty sure it's something in my conversion script thats giving me problems. What did I omit? Or does someone have an example of what the conversion script would look like for a tkinter GUI program? Also is it possible to divert the output .exe files to my desktop?

EDIT:

The error report said that I was missing init.tcl from {C:/Users/My_name/lib/tcl8.5}. So i made that directory and put a copy of init.tcl there. Now when I try to run the .exe it states that MSVCR90.dll is missing from my computer and is needed to run my program.

Also this is python 2.6.5 on Windows 7.

解决方案

For your original problem I can't say what exactly the problem is, but usually it helps with trial-and-error to guess missing files and directories. If you know what you're missing, add them to your packages (for python modules) or data_files (for other files).

The second problem is the result of some c-modules (and python itself) being build with MS Visual Studio, thus having a dependency to the MS Visual C++ 9.0 (2008) runtime. You can solve this by either:

  • owning a copy of Visual Studio (Express Edition doesn't count), so that you are permitted to redistribute the MSVCR dependencies (under the condition that you forbid your users reengeneering etc. of the dependend parts)

  • pointing your users to the download of the MS Visual C++ 2008 Redistributable package at Microsoft.

这篇关于带有 Tkinter 的 Py2exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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