这个错误我遇到不止一次了,经常忘!!!这里记一下!!!
完整报错示意:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/azimuth/model_comparison.py", line 1, in <module>
import azimuth.predict as pd
File "/usr/local/lib/python2.7/dist-packages/azimuth/predict.py", line 7, in <module>
import util
File "/usr/local/lib/python2.7/dist-packages/azimuth/util.py", line 2, in <module>
import matplotlib.pylab as plt
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pylab.py", line 252, in <module>
from matplotlib import cbook, mlab, 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 63, in pylab_setup
[backend_name], 0)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
from . import tkagg # Paint image to Tk photo blitter extension.
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/tkagg.py", line 5, 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
python2.7用agg做后端的,所以在import matplotlib.pylab前加上matplotlib.use(“agg”)即可。看这里的报错,只要去
/usr/local/lib/python2.7/dist-packages/azimuth/util.py 这里修改前几行即可。
...
import matplotlib # 添加
matplotlib.use("agg") # 添加
import matplotlib.pylab as plt
...