python中使用import matplotlib.pyplot as plt的plt保存图片的时候,前三次总是没问题,第四次总是报错。
报错如下:
Exception ignored in:
Traceback (most recent call last):
File "C:PythonPython36libtkinter__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Exception ignored in:
Traceback (most recent call last):
File "C:PythonPython36libtkinter__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Exception ignored in:
Traceback (most recent call last):
File "C:PythonPython36libtkinter__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Tcl_AsyncDelete: async handler deleted by the wrong thread
解决办法:
# import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt
用下面的三行替换掉引用的一行即可



