Azimout's Linux weblog

Matplotlib in Php

with one comment

You can call Python code from within a Php script and get the return value and output like this:

exec('python', $output, $return);
foreach ($output as $line) print "$line<br/>";

To test if everything is ok for your web server to call the python script, try: sudo -u www-data python

From this I found out that the Python call import matplotlib was failing with the error:

RuntimeError: ‘/home/azimout’ is not a writable dir; you must set /home/azimout/.matplotlib to be a writable dir.

This can be resolved by adding the following line to your Python code before you import matplotlib: os.environ[ 'HOME' ] = '/tmp/'



Written by azimout

21/01/2011 at 10:19

Posted in Problems

One Response

Subscribe to comments with RSS.

  1. THANK YOU! I’ve been debuggins some cgi scripts, and didn’t realize I could specify the server user to run it. I was setting my writeable directory correctly, but the hidden .matplotlib folder was not writable by the server.


    30/08/2012 at 21:57

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: