Developers' Forum

Matplotlib

Matplotlib

by Andreas Siebel -
Number of replies: 7

Hello,

I tried setting up the python-sandpit, but I get the following error:

Matplotlib created a temporary config/cache directory at /tmp/matplotlib-8125qscx because the default path (/home/jobe00/.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 installed
In reply to Andreas Siebel

Re: Matplotlib

by Andreas Siebel -

I found the error:

pip3 uninstall matplotlib
apt-get install python3-matplotlib

Solved the problem

In reply to Andreas Siebel

Re: Matplotlib

by Laurent Berger -
Unfortunalety It does not work for me :

Mauvaise sortie de la notation :
Run result: Run error
Output:
{"epiloguehtml": "png;base64,
Matplotlib created a temporary config/cache directory at /tmp/matplotlib-yca8mrb_ because the default path (/home/jobe00/.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.
. L'exécution de votre programme a peut-être été interrompue (par exemple, une limite de temps ou une limite de mémoire dépassée).
In reply to Laurent Berger

Re: Matplotlib

by Laurent Berger -
It does not work because I use python 3.10.4 and that's not official distribution.

How can I set MPLCONFIGDIR in jobe config?
In reply to Laurent Berger

Re: Matplotlib

by Laurent Berger -
Ok solved i used those lines in template :

import getpass
import os
os.environ['MPLCONFIGDIR'] = "/tmp/" + getpass.getuser()
import matplotlib.pyplot as plt
import json
import base64
import subprocess
import re
import os.path

# Define lines of code to insert before student's code
PREFIX = ["import matplotlib",
"matplotlib.use('Agg')",
"import matplotlib.pyplot as __plt__",
]

def make_data_uri(filename): ......
In reply to Laurent Berger

Re: Matplotlib

by Richard Lobb -
Good fix! Our own workaround (e.g. see here) is

if 'MPLCONFIGDIR' not in os.environ or os.environ['MPLCONFIGDIR'].startswith('/home'):
    import tempfile
    os.environ['MPLCONFIGDIR'] = tempfile.mkdtemp()

Would you mind telling us what question type you're using as your starting point? It looks like one of our own (University of Canterbury) in-house types. Some of the ones lying around in various historic postings are very out-dated and probably should be deleted or edited to point to more recent versions. Hopefully yours isn't too old. It sounds like you've got it working, anyway.

In reply to Laurent Berger

Re: Matplotlib

by Richard Lobb -
Thanks for the info. Good to know that blog post has been useful. Since it's just introducing general principles, it's not something that will have gone out of date. Enjoy!