Python的Tkinter库的安装

谁都会走 提交于 2020-12-12 01:28:39

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
>>> 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!