如何让tkinter使用Ubuntu的默认Python 2.7安装?

我正在使用预装了Python 2.7.3的Ubuntu 11.10.

我通过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
我花了太多时间在这个问题上花了很多时间,所以希望我可以省去别人的麻烦.

我发现这个旧的bug报告被认为是无效的,提到了我遇到的确切问题,我有Tkinter.py,但它找不到模块_tkinter:http://bugs.python.org/issue8555

我使用apt-get安装了tk-dev软件包,并使用./configure,make和make install在Python2.7.3目录中重建了Python.现在我的Python2.7可以导入Tkinter,是的!

我有点恼火的是,在Python安装文档中根本没有提到tk-dev软件包….下面是Python中缺少模块的另一个有用资源,如果像我一样,有人应该发现它们缺少的比_tkinter.

Building Python and more on missing modules

相关文章

文章浏览阅读2.3k次,点赞4次,收藏22次。最近安装了CARLA预...
文章浏览阅读6.3k次,点赞5次,收藏15次。在清华镜像中下载U...
文章浏览阅读5k次。linux环境, python3.7.问题描述: 安装...
文章浏览阅读4.2k次,点赞4次,收藏17次。要安装这个 standa...
文章浏览阅读894次,点赞51次,收藏31次。在安卓使用vscode主...