在centos7 系统下,python导入matplotlib时,出现ImportError: No module named '_tkinter'
的错误:下面是具体提示
[root@localhost ~]# /share/soft/poretools/poretools/poretools_main.py hist /share/soft/poretools/test_data/
Traceback (most recent call last):
File "/share/soft/poretools/poretools/poretools_main.py", line 544, in
main()
File "/share/soft/poretools/poretools/poretools_main.py", line 538, in main
args.func(parser, args)
File "/share/soft/poretools/poretools/poretools_main.py", line 24, in run_subtool
import hist as submodule
File "/share/soft/poretools/poretools/hist.py", line 6, in
from matplotlib import pyplot as plt
File "/share/soft/python-2.7.15/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in
backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup() File "/share/soft/python-2.7.15/lib/python2.7/site-packages/matplotlib/backends/_init_.py", line 62, in pylab_setup
[backend_name], 0)
File "/share/soft/python-2.7.15/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in
from . import tkagg # Paint image to Tk photo blitter extension.
File "/share/soft/python-2.7.15/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 5, in
from six.moves import tkinter as Tk
File "/share/soft/python-2.7.15/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/share/soft/python-2.7.15/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/share/soft/python-2.7.15/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import(name)
File "/share/soft/python-2.7.15/lib/python2.7/lib-tk/Tkinter.py", line 39, in
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
首先使用以下命令查看模块是否存在
yum list installed | grep ^tk
通常原因是tkinter和tk-devel缺失
通过命令,下载响应模块
yum install -y tkinter yum install -y tk-devel
进入python 目录。重新编译(需重新编译)
cd /usr/local/Python3.6.4
./configure make make install
来源:
https://www.jianshu.com/p/0baa9657377f
https://blog.csdn.net/blueheart20/article/details/78763208
https://www.cnblogs.com/richerdyoung/p/8459109.html
https://blog.csdn.net/superrunner_wujin/article/details/65945452