Posts Tagged ‘Matplotlib’

Fix Matplotlib MPLCONFIGDIR error

April 17, 2012 Leave a comment

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


Install Matplotlib, Scipy on Mac

February 12, 2012 Leave a comment

Struggling for a while to install matplotlib on my mac, finally find this one works:

First install brew: <>

And following the instruction posted here.

$ brew install python
 $ brew install gfortran
 $ brew install pkg-config
 $ easy_install pip
 $ pip install numpy
 $ cd $HOME
 $ git clone
 $ cd matplotlib
 $ python build
 $ python install

Well, then continue for my scipy 🙂

Here’s a ‘investigation‘ that i found, very useful. The official scipy/numpy site only say that CC, XCC, etc needs to be changed, but not for the fortran part. For my case, I did’t export the CC, etc — it not works for me, but I deed have fcompile specified.

mkdir ~/tmp
cd ~/tmp
git clone
cd scipy
python build --fcompiler=gfortran
sudo python install

Install nose:

sudo pip install nose
Categories: Uncategorized Tags: ,