Python 导入matplotlib报错 - ImportError: No module named Tkinter
程序员文章站
2022-04-28 19:32:03
...
摘要
今天在安装导致matplotlib包的时候报错如下,提示如下报错
>>> 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
>>> from Tkinter import *
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Tkinter
环境
[email protected]/1 $ cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
i-hruu3270 [~] 2017-05-10 15:11:00
[email protected]/1 $ python -V
Python 2.7.5
Tkinter VS tkinter
根据Python介绍发现 在Python2 和Python3 中该包名称是不一样的,在 python2
中叫Tkinter
; 在python3
中叫tkinter
Refer to
Tkinter — Python interface to Tcl/Tk
Note Tkinter has been renamed to tkinter in Python 3.
The 2to3 tool will automatically adapt imports when converting your
sources to Python 3.
Fix
install tkinter under centoer by yum
yum install -y tkinter
Verify
>>>
>>> import Tkinter
>>> import matplotlib.pyplot as plt
>>>
推荐阅读
-
解决pycharm终端/cmd运行python脚本报错“ImportError/ModuleNotFoundError:No Module named ...”
-
python自动化测试之web运行代码报错:importError:no module named selenium
-
python3报错“ImportError: No module named ‘MySQLdb'”
-
Python3 ImportError: No module named '_tkinter'
-
python2 报错 ImportError: No module named _internal
-
详解python导入模块时提示ImportError: No module named Crypto的原因
-
详解python导入模块时提示ImportError: No module named Crypto的原因
-
Python 导入matplotlib报错 - ImportError: No module named Tkinter
-
import matplotlib报错:No module named '_tkinter', please install the python3-tk package
-
python3.6导入flask.ext.wtf模块报错:No module named 'flask.ext'