title: Setting Matplotlib MPLCONFIGDIR: consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data
body: <p>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"</p>
  
  <p>Then I found $MPLCONFIGDIR are empty. So I set it like this:</p>
  
  <pre><code>lab@base:~$ export MPLCONFIGDIR=~/website/graph
  lab@base:~$ echo $MPLCONFIGDIR
  /home/lab/website/graph
  </code></pre>
  
  <p>This path is the directory where I want to store images created by Matplotlib.
  Then I made sure this setting in python command line:</p>
  
  <pre><code>&gt;&gt;&gt; import matplotlib
  &gt;&gt;&gt; import os
  &gt;&gt;&gt; os.environ.get('MPLCONFIGDIR')
  '/home/lab/website/graph'
  </code></pre>
  
  <p>BUT, in the django project which is deployed in Apache with mod_wsgi, the above-mentioned error still exits. I added the below lines:</p>
  
  <pre><code>import os
  os.environ['MPLCONFIGDIR'] = "/home/lab/website/graph"
  print(os.environ.get('MPLCONFIGDIR'))
  </code></pre>
  
  <p>It prints "None"!  </p>
  
  <p>Can anyone help me?</p>
  
  <p>Thanks.</p>