添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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"])

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.

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 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.

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\

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]"

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.

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 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?

An excellent solution, but is there a simple explanation for why py2exe causes this? Is this a bug? Has this been reported? – ecoe Oct 6, 2013 at 22:23

A correct Tcl and Tk installation will have the right value of those environment variables baked into it during build time; they only really exist to permit testing prior to installation (very useful for the developers of Tcl/Tk, best avoided for everyone else). If they're not connected up properly, or are finding the wrong version of the script libraries, there's a serious problem with your installation. (Note that this does mean that you should not normally move things around after installation, but that's not too much of a problem for most people.)

The usual advice in this sort of situation is to wipe the Tcl and Tk installations and start again, making sure that the correct installation location is specified to configure via the --prefix option. I have no idea how the addition of Python into the mix affects things.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.