I am using Linux server to set up a django project. I got this error: "Failed to create /var/www/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data"

Then I found $MPLCONFIGDIR are empty. So I set it like this:

lab@base:~$ export MPLCONFIGDIR=~/website/graph
lab@base:~$ echo $MPLCONFIGDIR
/home/lab/website/graph

This path is the directory where I want to store images created by Matplotlib. Then I made sure this setting in python command line:

>>> import matplotlib
>>> import os
>>> os.environ.get('MPLCONFIGDIR')
'/home/lab/website/graph'

BUT, in the django project which is deployed in Apache with mod_wsgi, the above-mentioned error still exits. I added the below lines:

import os
os.environ['MPLCONFIGDIR'] = "/home/lab/website/graph"
print(os.environ.get('MPLCONFIGDIR'))

It prints "None"!

Can anyone help me?

Thanks.

Edit
Report