每次我试图运行import matplotlib
我有错误ImportError: No module named Tkinter
下面列出的输出结果
Python 2.7.5 (default, Aug 2 2016, 04:20:16)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/usr/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
ImportError: No module named Tkinter
我尝试安装tk.x86_64
tk-devel.x86_64
个软件包并尝试重新安装python软件包,但错误仍然出现。
我也尝试import Tkinter
,但我收到了以下错误
Python 2.7.5 (default, Aug 2 2016, 04:20:16)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] 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
有没有人为此错误找到解决方法?
答案 0 :(得分:2)
我尝试从以下链接安装python2.7.5的tkinter包:
tkinter package
另外我发现tkinter包有依赖库libTix.so()(64bit),我从以下链接获得它:libTix.so()(64bit) package
之后,我安装了两个,然后我可以import Tkinter
和import matplotlib.pyplot as plt
没有错误。
答案 1 :(得分:1)
我的2美分。打开终端并键入以下内容。
$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>
如果你没有得到如下所示的错误,那么你的Tkinter很好,问题在于matplotlib。然后尝试删除并重新安装matplotlib。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tkinter
答案 2 :(得分:1)
我在ubuntu16.04上使用python2.7.12。 我用这个命令安装了它:
sudo apt-get install python-tk
答案 3 :(得分:0)
尽管安装了python3-tk和tkinter-dev,我仍然收到python3.5的错误“ ImportError:No module named'_tkinter'” 。
它在以下文件中显示错误:
文件“ /usr/local/lib/python3.5/tkinter/init.py”,第35行,在 import _tkinter#如果失败,则可能没有为Tk配置Python
通过从/ usr / bin运行python,就像从终端运行 /usr/bin/python3.5 一样,对我来说就解决了!
简而言之,请确保从终端运行的python版本已安装并配置了tkinter :)
我的电脑配置:带有默认python2.7和python3.5的Ubuntu16.04
答案 4 :(得分:0)
我在RHEL 7机器上遇到了同样的问题。没有python-tk
软件包可以安装。我找到了解决方案here,为我解决了这个问题:
sudo yum install tkinter
这应该适用于使用Python 2的RHEL计算机。