Ask coding questions

← Back to all posts
Matplotlib causing stuck web server
h
cardstdani

I have created a web server application on Replit using flask and it needs to use matplotlib library. The problem is that it gets stuck every time the server starts. This seems to be solved by removing matplotlib from the code.

This is what I get on the console before it freezes:
`Matplotlib created a temporary config/cache directory at /tmp/matplotlib-jvbhc0qv because the default path (/config/matplotlib) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.

Python 3.8.2 (default, Feb 26 2020, 02:56:10)

  • Serving Flask app 'app' (lazy loading)
  • Environment: production
    WARNING: This is a development server. Do not use it in a production deployment.
    Use a production WSGI server instead.
  • Debug mode: off
  • Running on all addresses.
    WARNING: This is a development server. Do not use it in a production deployment.
  • Running on http://172.18.0.191:8080/ (Press CTRL+C to quit)`

As you can see, it shows a screen when it's supposed to show the matplotlib output, but I don't need to show anything on the editor screen. I have also tried to change the backend of matplotlib but it doesn't work either.

The only way I managed to "solve" this is by creating a new Repl and transferring all the code, but this solution only works one time before it gets stuck again. Any solution would be very helpful.

This is the function that uses the library, it's only creating an image to send it to the client, it's not showing any graph on screen:

Voters
cardstdani
Comments
hotnewtop
StarkOdinson

This is so annoying because I'm not even using plot.show() but it automatically shows the mpl window when I don't want it to...

VulcanWM

sadly you can't use matplotlib at the same time as flask as then the flask won't show

cardstdani

@VulcanWM Does it work with django?

NFadhlurrahman

You cannot use GUI and web server on replit together. So matplotlib doesn't work with django @cardstdani

VulcanWM

No web apps :/ @cardstdani