0

I have an existing Python 2.4 and it is working properly with tkinter as I tested it using

python

import _tkinter

import Tkinter Tkinter._test()

Now, I have installed python 2.5.2 but when I try the same tests (with the newer version), it returns (but the same tests are working for the previous version)

ImportError: No module named _tkinter

I know that tcl8.5 and tk8.5 are installed on my machine as the following commands return there locations

whereis tcl tcl: /usr/lib/tcl8.4 /usr/local/lib/tcl8.5 /usr/local/lib/tcl8.4 /usr/share/tcl8.4

whereis tk tk: /usr/lib/tk8.4 /usr/local/lib/tk8.5 /usr/share/tk8.4

Any ideas how do I make my newer python version work with tkinter?

4

1 回答 1

3

您找到的文件用于直接链接到 tcl/tk。Python 也依赖于另一个库:_tkinter.so。它应该在 /usr/lib/python2.5/lib-dynload/_tkinter.so 中。
你是怎么安装python2.5的?如果您使用的是 Debian 或 Ubuntu,则需要安装 python-tk 包以获得 Tkinter 支持。

如果 _tkinter.so 文件在那里,您的环境可能会导致问题。如果

python -E -c "导入 Tkinter;Tkinter._test()"

成功了,但是

python -c "导入 Tkinter;Tkinter._test()"

失败,那么问题在于您的环境是如何设置的。检查 PYTHONPATH 的值是否设置正确。

于 2009-11-20T21:46:00.667 回答