如何使用 py2exe 更正 TCL_LIBRARY 和 TK_LIBRARY [英] How to correct TCL_LIBRARY and TK_LIBRARY with py2exe

查看:53
本文介绍了如何使用 py2exe 更正 TCL_LIBRARY 和 TK_LIBRARY的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个单独的 slideshow.py 文件来使用 Tkinter 小部件显示一些照片校正,它在我的 Windows 上完美运行linux.为了让它在没有安装 python 和 tcl 的 windows 上运行,我使用 py2exe 将它编译成一个 win32 可执行文件,setup.py 很简单:

I made a single slideshow.py file to display some photo correction with Tkinter widget, it runs perfectly on my windows & linux. To made it run on windows without python and tcl installed, I use py2exe to compile it into a win32 executable, setup.py is simple:

from distutils.core import setup
import py2exe
setup(windows=["slideshow.py"])

然后我运行python setup.py py2exe",它在 c:\Users\d2xia\ccm_wa\utils\tfps\ 和tcl"、library.zip"、slideshow"中生成一个dist"文件夹.exe"等等.

Then I run "python setup.py py2exe", it generate a "dist" folder in c:\Users\d2xia\ccm_wa\utils\tfps\, and "tcl", "library.zip", "slideshow.exe" and so on under it.

当我运行 slideshow.exe 时出现错误:

When I run slideshow.exe it errors:

Traceback (most recent call last):
  File "slideshow.py", line 45, in <module>
  File "Tkinter.pyc", line 1685, in __init__
_tkinter.TclError: Can't find a usable init.tcl in the following directories: 
    C:/Users/d2xia/ccm_wa/utils/tfps/lib/tcl8.5 C:/Users/d2xia/ccm_wa/utils/tfps/lib/tcl8.5 C:/Users/d2xia/ccm_wa/utils/lib/tcl8.5 C:/Users/d2xia/ccm_wa/utils/tfps/library C:/Users/d2xia/ccm_wa/utils/library C:/Users/d2xia/ccm_wa/utils/tcl8.5.11/library C:/Users/d2xia/ccm_wa/tcl8.5.11/library

tcl8.5 和 tk8.5 实际上是在 "tcl" 文件夹下,但是 py2exe 生成的 exe 似乎仍然在 "lib" 或 "library" 下,似乎没有设置正确的 TCL_LIBRARY 和 TK_LIBRARY.

tcl8.5 and tk8.5 actually resides under the "tcl" folder, but it seems the exe generated by py2exe still looks under "lib" or "library", it seems it doesn't set the correct TCL_LIBRARY and TK_LIBRARY.

即使我将tcl"重命名为lib",它仍然会出现相同的错误.

Even if I rename the "tcl" to "lib", it still get the same errors.

set TCL_LIBRARY=c:\Users\d2xia\ccm_wa\utils\tfps\dist\tcl\tcl8.5\
set TK_LIBRARY=c:\Users\d2xia\ccm_wa\utils\tfps\dist\tcl\tk8.5\

然后slideshow.exe产生一些新的错误:

then slideshow.exe generate some new errors:

c:/Users/d2xia/ccm_wa/utils/tfps/dist/tcl/tcl8.5/init.tcl: version conflict for package "Tcl": have 8.5.11, need exactly 8.5.2
version conflict for package "Tcl": have 8.5.11, need exactly 8.5.2
    while executing
"package require -exact Tcl 8.5.2"
    (file "c:/Users/d2xia/ccm_wa/utils/tfps/dist/tcl/tcl8.5/init.tcl" line 20)
    invoked from within
"source c:/Users/d2xia/ccm_wa/utils/tfps/dist/tcl/tcl8.5/init.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 [list source $tclfile]"

我在 C:\apps\git\lib\tcl8.5 中有 Tcl 8.5.11和 Tcl 8.5.2 在 C:\Python27\tcl\tcl8.5好像我用python运行的时候,在python安装路径中寻找tcl,但是py2exe在git安装路径中看起来是不同的副本.

I have Tcl 8.5.11 in C:\apps\git\lib\tcl8.5 and Tcl 8.5.2 in C:\Python27\tcl\tcl8.5 It seems when I run with python, it looks for tcl in python installation path, but py2exe looks a different copy in the git installation path.

那么问题就变成了:1. 创建 dist 时如何将正确的 tcl8.5 副本分配"给 py2exe?2.如何让生成的可执行文件知道dist中的tcl路径?tcl"而不是lib"或library"

So then questions become: 1. How to "assign" a correct tcl8.5 copy to py2exe when create the dist? 2. How to let the generated executable aware of the tcl path in the dist? "tcl" instead of "lib" or "library"

推荐答案

Tcl version 8.5.11 &8.5.2 冲突通过手动替换tcl8.5、tk8.5、tcl85.dll和tk85.dll与python安装路径的冲突解决,我相信也可以通过更改路径环境变量来解决.但是我还是要手动设置TCL_LIBRARY和TK_LIBRARY,我做了一个windows批处理包装器test.bat:

Tcl version 8.5.11 & 8.5.2 conflicts solved by manually replace tcl8.5, tk8.5, tcl85.dll and tk85.dll with the ones from python installation path, I believe it can also be solved by change the path environment variable. But I still have to manually set the TCL_LIBRARY and TK_LIBRARY, I made a windows batch wrapper test.bat:

set TCL_LIBRARY=.\tcl\tcl8.5\
set TK_LIBRARY=.\tcl\tk8.5\
slideshow.exe %1

这行得通,有什么更好的主意吗?

This works, any better ideas?

这篇关于如何使用 py2exe 更正 TCL_LIBRARY 和 TK_LIBRARY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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