2012-08-01 132 views
3

我使用Ubuntu 11.10,它预装了Python 2.7.3。如何让tkinter使用Ubuntu的默认Python 2.7安装?

我安装了python3封装,python3-tk的包,通过apt-get安装,和他们一起工作“开箱即用”。

然而,尽管我已经安装了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 
+0

我知道在Python 3里,Tkinter的模块被小写( “Tkinter的”)。所以你可以尝试“导入tkinter”。然后,这个人(http://ubuntuforums.org/showthread.php?t=1699456)似乎也有类似的问题,但它看起来比使用错误的名称更深层。 – seaotternerd 2012-08-01 03:47:02

+0

我试过了小写字母和大写......都没有工作,只有大写的给我提供了更具体的错误信息。 – 2012-08-01 03:58:12

回答

11

我想通了花在这个问题之后了太多的时间,所以希望我能救别人的麻烦。

我发现这个古老bug报告认为,所提到我有确切的问题无效的,我有Tkinter.py,但它无法找到该模块_tkinter:http://bugs.python.org/issue8555

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

我有点恼火的是,TK-dev软件包是不是Python的安装文件中都提到....下面是失踪模块在Python如果像我一样另一个有用的资源,应该有人发现他们比_tkinter缺失更多。

Building Python and more on missing modules

+0

如果你在'./configure'之前编译了python下的fedora do'sudo yum install tk-devel' – User 2013-01-07 13:04:52

0

我有同样的问题与python3.4(导入错误:没有模块名为 '_tkinter')

sudo apt-get install tk-dev 

得Python源目录

./configure 
make 
sudo make install 
0

以下解决问题我在Linux Mint的16:

sudo apt-get install tk-dev python-tk 

我使用的virtualenv但不想编译蟒蛇,为了使Python支持TK,蟒蛇-TK应安装。

相关问题