Home > Python, Web > Fix Matplotlib MPLCONFIGDIR error

Fix Matplotlib MPLCONFIGDIR error

When using Apache + python-cgi, I encounter this error:

<type ‘exceptions.RuntimeError’>: Failed to create /$dirstring$/common/.matplotlib; consider setting MPLCONFIGDIR to a writable directory for matplotlib configuration data 

An official explanation of MPLCONFIGDIR is here.

MPLCONFIGDIR This is the directory used to store user customizations to matplotlib, as well as some caches to improve performance. If MPLCONFIGDIR is not defined, HOME/.matplotlib is used by default.

It turns out that on my windows machine HOME/.matplotlib is now writable. Here’s a way to simply bypass this problem.

Find out the place where you first import matplotlib, right before it, set the $HOME dir to a temporary dir where it’s writable:

For example, I was importing matplotlib in an indirect way through “from scipy.cluster.vq import kmeans2“, so right before it, do

os.environ[‘HOME’] = r’C:\……\Apache2.2\htdocs\tmp’

from scipy.cluster.vq import kmeans2

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: