Skip to content
← Back to Community
matplotlib => mp.use('Agg')
Profile icon
h
has Hacker Plan
BenjaminPS

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 [earned 5 cycles]
View Answer
Voters
Profile icon
BenjaminPS
Comments
hotnewtop
Profile icon
Coder100

Create a .env file. Inside put:

MPLCONFIGDIR=[your folder here]

and then turn [your folder here] to whatever

Profile icon
BenjaminPS

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 ?

Profile icon
Coder100
Profile icon
Coder100

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

Profile icon
BenjaminPS

@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

Profile icon
Coder100

epic i found something for you!
click
@BenjaminPS

Profile icon
BenjaminPS

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

Profile icon
Coder100

yay!! np :) @BenjaminPS

Profile icon
acal1

@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

Profile icon
BenjaminPS

Hi @acal1

Write:

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

as first lines of the code.

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

MPLCONFIGDIR=[/opt/myapplication/.config/matplotlib]

inside.

This should make it work.

Profile icon
acal1

@BenjaminPS Thanks!! I'll give it a try when I sit down with this again.

Profile icon
BenjaminPS

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 ?

Profile icon
JohnKershaw

@BenjaminPS Adding this:

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

before

import matplotlib

works for me