[mod_python] matplotlib and mod_python

David Fraser davidf at sjsoft.com
Tue Mar 6 04:49:25 EST 2007

Rajarshi Guha wrote:
> Hi, I have a mod_python based application in which I would like to
> generate a chart using matplotlib.
> Currently, when I try to call the function that generates the chart I
> get a 'HOME not writable' error. I realize why this is happening and so
> I modified my apache startup script to export a HOME directory of '/tmp'
> When this is done, the chart is generated, but when I try to dump the
> chart to a file using:
> canvas.print_figure( ... )
> the file is always created in /tmp (i.e., the value of HOME), rather
> than in the file that I specify (which is in a current directory that is
> writable by apache).
> Has anybody successfully used matplotlib in a mod_python application, to
> actually save a chart to a disk file?
> (I realize that one way would be to send back the raw image bytes, but
> the image is supposed to be a part of an HTML page, so I can't go down
> that path)
> Any pointers would be greatly appreciated.
A much better way IMHO is to generate the image in a Python handler in
response to the request for the image.
Then you can send back the raw image bytes without saving them to disk.
You basically need to pass the parameters that are needed to generate
the image in the URL that you reference the image as in the HTML code
This avoids all kinds of potential problems with state, multiple image
requests overlapping, etc


More information about the Mod_python mailing list