Ask coding questions

← Back to all posts
matplotlib => mp.use('Agg')
h
BenjaminPS (2)

Hi all,
I've been using the command mp.use('Agg') with matplotlib to prevent Repl to create an interactive box (I only want to have the graphs saved in the "files" directly).

However since the last update I get this message when I run my Repl:

"Matplotlib created a temporary config/cache directory at /tmp/matplotlib-8gfs3tr6 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."

I don't really get it. Could someone give me a tip on how to solve this ?

Answered by Coder100 (19277) [earned 5 cycles]
View Answer
Comments
hotnewtop
Coder100 (19277)

Create a .env file. Inside put:

and then turn [your folder here] to whatever

BenjaminPS (2)

Thanks @Coder100 but this Repl I created is a tool used by others. However .env files cannot be accessed by other users. Will it still work ?

Coder100 (19277)

how unfortunate...
please do report this to feedback suggesting an env.env which is public to others and are used to set some environment variables that are not sensitive.

Anyways, overall, it should not be a big deal, it is just a warning on performance (which I doubt you will notice)

@BenjaminPS

BenjaminPS (2)

@Coder100 if it's a performance warning I'm happy to ignore it. Is there a way to skip this warning ? I tried warnings.filterwarnings("ignore", category=Warning) it did not work

Coder100 (19277)

epic i found something for you!
click
@BenjaminPS

BenjaminPS (2)

This worked like a charm \o/ Thanks a lot @Coder100

acal1 (0)

@Coder100 @BenjaminPS I tried this but still can't get things to work. Would appreciate a code block and instructions on the exact file directory to generate. I have matplotlib package installed already. Thanks in advance! My repl: https://repl.it/@acal1/randomForest1#main.py

BenjaminPS (2)

Hi @acal1

Write:

as first lines of the code.

Create an .env file (this is only accessibe by the owner of the REPL) and write:

inside.

This should make it work.

BenjaminPS (2)

I would be more than happy to "set the MPLCONFIGDIR environment variable to a writable directory" but which directory is writable ? And how can I ask matplotlib to write there ?

JohnKershaw (3)

@BenjaminPS Adding this:

import os
os.environ['MPLCONFIGDIR'] = os.getcwd() + "/configs/"

before

import matplotlib

works for me