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

前端 未结 2 1377
感动是毒
感动是毒 2021-02-07 05:55

I\'m using flask, matplotlib to save image and tensorflow to create a session. I\'m getting the above error when I run the following code. Does the flask route run on a separate

相关标签:
2条回答
  • 2021-02-07 06:31

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

    import matplotlib
    matplotlib.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.

    0 讨论(0)
  • 2021-02-07 06:48

    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.

    • Threaded client with the same issue
    • Running TKinter in a seperate thread
    • enter link description here
    0 讨论(0)
提交回复
热议问题