Problems running as CGI script (Apache and HOME variable)

Hello all,

Matplotlib raises this error when I import it as a CGI program:

RuntimeError: '/var/www' is not a writable dir; you must set
environment variable HOME to be a writable dir

I am a non-root user, and the Apache user's HOME =/var/www, so CGI
script raises an exception when that directory isn't writeable. There
is nothing to be done about the Apache users's environment variables,
or the writablity of that directory, as a non-root user :slight_smile:

It appears that matplotlib checks the HOME environment variable, then
the MATPLOTLIBDATA variable, and then goes on to check the
matplotlibrc starting with the current directory. But it raises an
exception if the home directory isn't writeable without checking the
rc file to see if the datapath inside it would work?

Is there a way to either prevent matplotilb from checking for HOME,
and go straight to the local matplotlibrc, or alternately have it
check the matplotlibrc if the HOME directory isn't writable?

Thanks,

Andrew

OK, scratch that. Typing it out helped me see where my assumptions
were screwy. You can set environment variables quite happily in
.htaccess.

If this gets past moderation, you can just do this:

SetEnv HOME /user/home/directory

In .htaccess and it fixes it right up :slight_smile:

路路路

On 11/4/05, Andrew P <grouch@...287...> wrote:

Hello all,

Matplotlib raises this error when I import it as a CGI program:

RuntimeError: '/var/www' is not a writable dir; you must set
environment variable HOME to be a writable dir

I am a non-root user, and the Apache user's HOME =/var/www, so CGI
script raises an exception when that directory isn't writeable. There
is nothing to be done about the Apache users's environment variables,
or the writablity of that directory, as a non-root user :slight_smile:

It appears that matplotlib checks the HOME environment variable, then
the MATPLOTLIBDATA variable, and then goes on to check the
matplotlibrc starting with the current directory. But it raises an
exception if the home directory isn't writeable without checking the
rc file to see if the datapath inside it would work?

Is there a way to either prevent matplotilb from checking for HOME,
and go straight to the local matplotlibrc, or alternately have it
check the matplotlibrc if the HOME directory isn't writable?

Thanks,

Andrew

Hej Andrew,
intersting solution! just a couple of days ago I was struggeling with
the same problem
I solved it by setting the environment variable from within my CGI script
the following is a template for a cgi that uses matplotlib to create a
png figure:

路路路

============
#!/usr/bin/python
import cgitb; cgitb.enable()

# set HOME environment variable to a directory the httpd server can write to
import os
myenv = os.environ
myenv['HOME'] = '/tmp/'

# chose a non-GUI backend
import matplotlib
matplotlib.use('Agg')

# construct your plot
from pylab import *
...

# save the plot as image
savefig(...)

On 11/5/05, Andrew P <grouch@...287...> wrote:

OK, scratch that. Typing it out helped me see where my assumptions
were screwy. You can set environment variables quite happily in
.htaccess.

If this gets past moderation, you can just do this:

SetEnv HOME /user/home/directory

In .htaccess and it fixes it right up :slight_smile:

On 11/4/05, Andrew P <grouch@...287...> wrote:
> Hello all,
>
> Matplotlib raises this error when I import it as a CGI program:
>
> RuntimeError: '/var/www' is not a writable dir; you must set
> environment variable HOME to be a writable dir
>
> I am a non-root user, and the Apache user's HOME =/var/www, so CGI
> script raises an exception when that directory isn't writeable. There
> is nothing to be done about the Apache users's environment variables,
> or the writablity of that directory, as a non-root user :slight_smile:
>
> It appears that matplotlib checks the HOME environment variable, then
> the MATPLOTLIBDATA variable, and then goes on to check the
> matplotlibrc starting with the current directory. But it raises an
> exception if the home directory isn't writeable without checking the
> rc file to see if the datapath inside it would work?
>
> Is there a way to either prevent matplotilb from checking for HOME,
> and go straight to the local matplotlibrc, or alternately have it
> check the matplotlibrc if the HOME directory isn't writable?
>
>
> Thanks,
>
> Andrew
>

-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

added a wiki entry for this, it can be found here:
http://www.scipy.org/wikis/topical_software/UsingMatPlotLibInACGIScript

路路路

On 11/5/05, frank h. <frank.hoffsummer@...287...> wrote:

Hej Andrew,
intersting solution! just a couple of days ago I was struggeling with
the same problem
I solved it by setting the environment variable from within my CGI script
the following is a template for a cgi that uses matplotlib to create a
png figure:

============
#!/usr/bin/python
import cgitb; cgitb.enable()

# set HOME environment variable to a directory the httpd server can write to
import os
myenv = os.environ
myenv['HOME'] = '/tmp/'

# chose a non-GUI backend
import matplotlib
matplotlib.use('Agg')

# construct your plot
from pylab import *
...

# save the plot as image
savefig(...)

On 11/5/05, Andrew P <grouch@...287...> wrote:
> OK, scratch that. Typing it out helped me see where my assumptions
> were screwy. You can set environment variables quite happily in
> .htaccess.
>
> If this gets past moderation, you can just do this:
>
> SetEnv HOME /user/home/directory
>
> In .htaccess and it fixes it right up :slight_smile:
>
> On 11/4/05, Andrew P <grouch@...287...> wrote:
> > Hello all,
> >
> > Matplotlib raises this error when I import it as a CGI program:
> >
> > RuntimeError: '/var/www' is not a writable dir; you must set
> > environment variable HOME to be a writable dir
> >
> > I am a non-root user, and the Apache user's HOME =/var/www, so CGI
> > script raises an exception when that directory isn't writeable. There
> > is nothing to be done about the Apache users's environment variables,
> > or the writablity of that directory, as a non-root user :slight_smile:
> >
> > It appears that matplotlib checks the HOME environment variable, then
> > the MATPLOTLIBDATA variable, and then goes on to check the
> > matplotlibrc starting with the current directory. But it raises an
> > exception if the home directory isn't writeable without checking the
> > rc file to see if the datapath inside it would work?
> >
> > Is there a way to either prevent matplotilb from checking for HOME,
> > and go straight to the local matplotlibrc, or alternately have it
> > check the matplotlibrc if the HOME directory isn't writable?
> >
> >
> > Thanks,
> >
> > Andrew
> >
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by:
> Tame your development challenges with Apache's Geronimo App Server. Download
> it for free - -and be entered to win a 42" plasma tv or your very own
> Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>