Python的Tkinter库的安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python的Tkinter库的安装相关的知识,希望对你有一定的参考价值。

 

在FCN代码中运行infer.py时出现如下错误:

File "infer.py", line 4, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/usr/local/lib/python2.7/dist-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/local/lib/python2.7/dist-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python2.7/dist-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
raise ImportError, str(msg) + ‘, please install the python-tk package‘
ImportError: No module named _tkinter, please install the python-tk package

 

解决办法:

Tkinter是Python的GUI widget。一般情况下Linux都没有自带,要自己安装。


1、确定Tkinter没有安装:
>>> import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 41, in ?
    raise ImportError, str(msg) + ‘, please install the python-tk package‘
ImportError: No module named _tkinter, please install the python-tk package
>>>

2、安装Tkinter:
$sudo apt-get install python-tk

 

3、安装成功:
>>> import Tkinter
>>> 






























以上是关于Python的Tkinter库的安装的主要内容,如果未能解决你的问题,请参考以下文章

deepin下安装python的Tkinter库

新安装的ubuntu,python为2.7.3,没有Tkinter,本机不能上网,如何安装tkinter及其他库 。

我Python的tkinter库的grid布局无效?怎么办?

Python 可嵌入 zip:安装 Tkinter

使用python 3.5在centos 6.5上安装tkinter

为啥通过 Homebrew 安装的 Python 不包括 Tkinter