【发布时间】:2012-07-29 22:21:35
【问题描述】:
我使用的是 Ubuntu 11.10,它预装了 Python 2.7.3。
我通过 apt-get install 安装了 python3 包和 python3-tk 包,它们“开箱即用”一起工作。
但是虽然我已经安装了 python-tk 包,但我不知道如何让 Python2.7 看到它。我尝试导入时收到以下错误消息。
import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
编辑:我还根据Python-tk package not recognized in Python 2.7.3 运行了以下内容,得到:
$ file /usr/lib/libtk8.5.so.0
/usr/lib/libtk8.5.so.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, stripped
$ uname -a
Linux bugbot 3.0.0-23-generic-pae #39-Ubuntu SMP Thu Jul 19 19:39:19 UTC 2012 i686 i686 i386 GNU/Linux
【问题讨论】:
-
我知道在 Python 3 中,Tkinter 模块是小写的(“tkinter”)。所以你可以尝试“import tkinter”。话又说回来,这个人(ubuntuforums.org/showthread.php?t=1699456)似乎也有类似的问题,但看起来它比仅仅使用错误的名字更深入。
-
我已经尝试过小写和大写...都没有工作,只有大写让我得到更具体的错误消息。