Py2exe 与 Tkinter

发布于 2024-09-28 05:02:21 字数 1374 浏览 7 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

-柠檬树下少年和吉他 2024-10-05 05:02:22

对于您最初的问题,我无法说出问题到底是什么,但通常它有助于通过反复试验来猜测丢失的文件和目录。如果您知道缺少什么,请将它们添加到您的packages(对于 python 模块)或data_files(对于其他文件)。

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

  • 拥有 Visual Studio 的副本(快速版不算),以便您可以重新分发 MSVCR 依赖项(条件是您禁止用户重新设计依赖项等)部件)

  • 引导您的用户下载 Microsoft 的 MS Visual C++ 2008 Redistributable 软件包。

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.

我不吻晚风 2024-10-05 05:02:22

我在 Virutalenv 网站上发现了一个错误,建议执行以下操作
https://github.com/pypa/virtualenv/issues/93

(适用于 Windows)
在您的目录“C:\Environments\VirtualEnv\Scripts\activate.bat”中
只需添加设置为您的 python 版本的 TCL 和 TK 的正确路径

set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python27\tcl\tk8.5"

,然后重新启动您的 cmd 或 shell

当我遇到此错误时,它对我来说非常有效。

I found a bug on the virutalenv site which suggested the following
https://github.com/pypa/virtualenv/issues/93

for windows
in your directory "C:\Environments\VirtualEnv\Scripts\activate.bat"
just add which are set to the right path to TCL and TK for your python version

set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5"
set "TK_LIBRARY=C:\Python27\tcl\tk8.5"

and restart your cmd or shell

It worked very well for me when I had this error.

风蛊 2024-10-05 05:02:22

py2exe 不能与模块一起使用,我听说过一个名为 c_freeze 的程序,它显然可以与模块一起使用,尝试一下吗? http://cx-freeze.sourceforge.net/

py2exe doesn't work with modules, i've heard of one called c_freeze which apparently works with modules, try that? http://cx-freeze.sourceforge.net/

谁与争疯 2024-10-05 05:02:22

关于MSVCR90.dll,请参阅这篇文章,它将其打包,可能不如让用户单独安装它更好。

另外,该帖子中的具体问题是我的,我仍然不明白根本原因。也就是说,完全卸载 python 并干净重建效果很好......也许这也是你的问题。 py2exe 给出运行时错误:创建图像太早

With respect to MSVCR90.dll, see this post which packages it and maybe less preferable than having user install it separately.

Also, the specific issue in that post was mine and i still don't understand root cause. That said, a complete uninstall python and clean rebuild worked great... maybe that is your issue too. py2exe gives RuntimeError: Too early to create image

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文