py2exe 中的 Tkinter 帮助
我正在尝试使用 py2exe 将基本 tkinter GUI 程序转换为 .exe。但是,我使用以下转换脚本遇到了错误。
# 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 是以下代码
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()
这是当我尝试运行新创建的 .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.
我很确定这是我的转换脚本中的某些内容给我带来了问题。我遗漏了什么?或者有人有 tkinter GUI 程序的转换脚本的示例吗?另外,是否可以将输出 .exe 文件转移到我的桌面?
编辑:
错误报告说我缺少{C:/Users/My_name/lib/tcl8.5}中的init.tcl。所以我创建了该目录并在其中放置了 init.tcl 的副本。现在,当我尝试运行 .exe 时,它指出我的计算机中缺少 MSVCR90.dll,并且需要运行我的程序。
这也是 Windows 7 上的 python 2.6.5。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Unix 世界中的此类错误通常是由于不正确的 PATH 设置或/和不正确安装的第三方模块(您正在使用的 GUI 模块)造成的。您是否看过这篇文章:py2exe 无法生成可执行文件?
Such errors in Unix world are usually due to incorrect PATH settings or/and incorrectly installed third party modules (the GUI ones you're using). Have you seen this post: py2exe fails to generate an executable ?