1

我尝试使用Canopy导入 Tk 失败:

In [1]: import Tkinter
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-a0c812564da3> in <module>()
----> 1 import Tkinter

/Applications/Canopy.app/appdata/canopy-1.0.0.1160.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-tk/Tkinter.py
in <module>()
     37     # Attempt to configure Tcl/Tk without requiring PATH
     38     import FixTk
---> 39 import _tkinter # If this fails your Python may not be configured for Tk
     40 tkinter = _tkinter # b/w compat for export
     41 TclError = _tkinter.TclError

ImportError: dlopen(/Applications/Canopy.app/appdata/canopy-1.0.0.1160.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-dynload/_tkinter.so,
2): Library not loaded:
/Library/Frameworks/Python.framework/Versions/111.222.33344/lib/libtcl8.5.dylib
  Referenced from:
/Applications/Canopy.app/appdata/canopy-1.0.0.1160.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-dynload/_tkinter.so
  Reason: image not found

和:

$ ls -l /Applications/Canopy.app/appdata/canopy-1.0.0.1160.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-dynload/_tkinter.so
-rwxr-xr-x@ 1 cassio  admin  66184 Mar 25 17:54
/Applications/Canopy.app/appdata/canopy-1.0.0.1160.macosx-x86_64/Canopy.app/Contents/lib/python2.7/lib-dynload/_tkinter.so

$ ls -l /Library/Frameworks/Python.framework/Versions/111.222.33344/lib/libtcl8.5.dylib
ls: /Library/Frameworks/Python.framework/Versions/111.222.33344/lib/libtcl8.5.dylib:
No such file or directory

我以为 Tk/Tcl 预装了 python。我怎样才能让它工作?

4

2 回答 2

0

实际上,来自 Enthought 的 Jonathan March 通过在 Enthought 知识库网站上发布了一个解决方法来回应这个问题,其中涉及更改一些动态库和更改默认 UI 后端。

于 2013-05-10T17:16:27.917 回答
0

我有同样的问题:Tk import failed。但是当它没有失败时 - 什么都没有显示,过了一会儿 Python 内核就死了。

我不知道如何修复它,但从终端运行有帮助(我使用的是 OS X 10.6.8)。我刚刚输入(对于名为 test.py 的文件)

$python test.py
于 2013-05-09T16:51:50.463 回答