python中使用import matplotlib.pyplot as plt的plt保存图片的时候,前三次总是没问题,第四次总是报错。
报错如下:
Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x000001B31B4E6470>>
Traceback (most recent call last):
File "C:\Python\Python36\lib\tkinter\__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x000001B31B4D5EB8>>
Traceback (most recent call last):
File "C:\Python\Python36\lib\tkinter\__init__.py", line 3507, in __del__
self.tk.call('image', 'delete', self.name)
RuntimeError: main thread is not in main loop
Exception ignored in: <bound method Image.__del__ of <tkinter.PhotoImage object at 0x000001B31B52F128>>
Traceback (most recent call last):
File "C:\Python\Python36\lib\tkinter\__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
用下面的三行替换掉引用的一行即可