Error with executing CGI script - writable directory for matplotlib
Question: I know that the similar problem was solving in this topic:

[Setting Matplotlib MPLCONFIGDIR: consider setting MPLCONFIGDIR to a writable
directory for matplotlib configuration
data](http://stackoverflow.com/questions/9827377/setting-matplotlib-
mplconfigdir-consider-setting-mplconfigdir-to-a-writable-dir)

, but I have problem with executing CGI script. I use HTML fomular to input
some data, and based on these data make OLS model by statsmodels and result
want print as HTML page. If I execute python script it give me this error:

<http://textuploader.com/5nrhf>

Basicaly I get error - `Failed to create /var/www/.matplotlib; consider
setting MPLCONFIGDIR to a writable directory for matplotlib configuration
data`

I red about setting the MPLCONFIGDIR in code before you import matplotlib and
ake sure the directory has permissions such that it can be written to by the
app like this:

    
    
    import os
    os.environ['MPLCONFIGDIR'] = "/home/lab/website/graph"
    import matplotlib
    

or

    
    
    import os
    import tempfile
    os.environ['MPLCONFIGDIR'] =tempfile.mkdtemp()
    import matplotlib
    

but I don´t import matplotlib module in my script, only
`CGI`,`statsmodels.api`,`MySQLdb` and `numpy`

If you want, here is my CGI script - <http://textuploader.com/5nrx4>

I don´t know, if I must set permissions for matplotlib folder, to can be
writable by me as executro of CGI script or somehow set matplotlib folder to
different path (writable by me). BTW I dont own server it is just school
server.


Answer: You don't explicitly import `matplotlib`, but `statsmodels.api` imports
`pandas`, and in turn `pandas` imports `matplotlib` (you can see all tht
reading through your traceback).

So, you still need to have a writable `MPLCONFIGDIR` in order to run your
script. You already have the answer how to do that, but in case you want to
read more about it, there is some documentation
[here](http://matplotlib.org/faq/environment_variables_faq.html#envvar-
MPLCONFIGDIR) about setting `matplotlib` environment variables.

* * *

It should be enough to just add this in your file before you import
`statsmodels.api`:

    
    
    import os
    os.environ['MPLCONFIGDIR'] = "/home/lab/website/graph"
    

