问题描述
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>
另一方面...
Python 3.2 (r32:88445, Mar 25 2011, 19:28:28)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Tkinter
我检查了突触,Tkinter 已安装.然后我发现了这个--
I checked synaptic, Tkinter is installed. Then I found this--
如果失败并显示No module named _tkinter",则需要修改您的 Python 配置以包含此模块(这是一个用 C 实现的扩展模块).不要编辑模块/设置(它已过时).您可能必须安装 Tcl 和 Tk(使用 RPM 时,也安装 -devel RPM)和/或编辑 setup.py 脚本以指向安装 Tcl/Tk 的正确位置.如果您在默认位置安装 Tcl/Tk,只需重新运行make"即可构建 _tkinter 扩展.
我猜测 tkinter 仍然与我电脑中的旧 python 相关联.如何更改它以便 python3 可以使用 tkinter?
I am guessing that tkinter is still associated with the old python in my pc. How do I change that so python3 can use tkinter?
推荐答案
既然你提到了突触,我想你是在使用 Ubuntu.您可能需要运行 update-python-modules 为 Python 3 更新您的 Tkinter 模块.
Since you mention synaptic I think you're on Ubuntu. You probably need to run update-python-modules to update your Tkinter module for Python 3.
EDIT:运行 update-python-modules
EDIT: Running update-python-modules
首先,确保你已经安装了python-support
:
First, make sure you have python-support
installed:
sudo apt-get install python-support
然后,使用 -a
选项运行 update-python-modules
以重建所有模块:
Then, run update-python-modules
with the -a
option to rebuild all the modules:
sudo update-python-modules -a
我不能保证你的所有模块都能构建,因为 Python 2 和 Python 3 之间有一些 API 变化.
I cannot guarantee all your modules will build though, since there are some API changes between Python 2 and Python 3.
这篇关于在 Ubuntu 上找不到 Tkinter 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!