调用matplotlib时tkinter报错

报错信息:

  File "/usr/local/lib/python3.6/tkinter/__init__.py", line 36, in 
    import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'

解决办法:

将原来的

import matplotlib.pyplot as plt

改为:

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt

参考: https://stackoverflow.com/a/4935945/6354733

你可能感兴趣的:(调用matplotlib时tkinter报错)