RuntimeError: main thread is not in main loop with Matplotlib and Flask RuntimeError: main thread is not in main loop with Matplotlib and Flask flask flask

RuntimeError: main thread is not in main loop with Matplotlib and Flask


I was on the same situation, Flask with Matplotlib combo.What worked for me is to specify Agg as Matplotlib backend.

import matplotlibmatplotlib.use('Agg')import matplotlib.pyplot as plt# Your code here

You can refer to Matplotlib documentation (Matplotlib in a web application server) for the details.


apparently this is an issue with TKinter. You don't have your full error message posted (you really should do that), but I'm working on something very similar so I'm 99.9% sure your problem is the same as mine. I'm building an app with tensorflow, flask, blah blah. I get the same error, intermittently (sometimes it works). Here are some links to similar questions. I hope this helps! I think my solution will be moving away from matplotlib.