您的位置:首页 > 编程语言 > Go语言

matplotlib 第二次执行报错在 django web服务中

2017-09-14 18:25 190 查看
报错内容如下:


Exception RuntimeError: RuntimeError('main thread is not in main loop',) in <bound method PhotoImage.del of < Tkinter.PhotoImage instance at 0x7f347192b5a8>> ignored


解决方法:最代码最顶层加:

import matplotlib
matplotlib.use('Agg')

要在 pylab 和 matplotlib.pyplot 之前,否则无效。

这里有一个容易让人忽视的地方,因为有些python 库 也包含了pylab 或 matplotlib.pyplot, 如果上述代码未加在他们之前,则会无效,不熟悉的话很难找到原因,所以最保险的是加代码文件的在最顶层。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: