On May 17, 8:31 pm, Graham Dumpleton <[email protected]> wrote: > On 18 May 2010 11:06, svanheulen <[email protected]> wrote: > > > I'm trying to use matplotlib with mod_wsgi. I'm getting 500 errors the > > first time the page loads but it displays correctly if you refresh the > > page immediately. If I then wait for a while and refresh again it > > gives a 500 error again. Seems like it has something to do with the > > way mod_wsgi loads things. Any ideas? > > Looks like a circular import problem in matplotlib. > > Try adding as first import, before other matplotlib imports: > > import matplotlib > import matplotlib.cbook > > See if that even works. > That seems to do the trick. Thanks! > > > > Here are the versions I'm using: > > > Apache 2.2.14 (worker MPM) > > mod_wsgi 2.8 > > Python 2.6.5 > > matplotlib 0.99.1.2 > > > Here is the error that occurs in my Apache logs: > > > mod_wsgi (pid=1530): Target WSGI script '/home/user/graph.wsgi' cannot > > be loaded as Python module. > > mod_wsgi (pid=1530): Exception occurred processing WSGI script '/home/ > > user/graph.wsgi'. > > Traceback (most recent call last): > > File "/home/user/graph.wsgi", line 6, in <module> > > from matplotlib.backends.backend_agg import FigureCanvasAgg > > File "/usr/lib/pymodules/python2.6/matplotlib/backends/ > > backend_agg.py", line 28, in <module> > > from matplotlib.backend_bases import RendererBase,\\ > > File "/usr/lib/pymodules/python2.6/matplotlib/backend_bases.py", > > line 29, in <module> > > import matplotlib.cbook as cbook > > AttributeError: 'module' object has no attribute 'cbook' > > > Here is the source of graph.wsgi: > > > import os > > os.environ['HOME'] = '/tmp' > > Setting HOME like that is not a good idea. > > Suggest you use WSGIDaemonProcess/WSGIProcessGroup (ie., daemon mode) > and specific user/group options to WSGIDaemonProcess to designate > daemon process to run as a user different to Apache user which has an > actual home directory. > > This will solve Python egg cache issues along with other things as well. > > Graham > Yeah, that was just a quick fix while I was trying to troubleshoot. > > > > import StringIO > > from matplotlib.backends.backend_agg import FigureCanvasAgg > > from matplotlib.figure import Figure > > > def application(environ, start_response): > > output = StringIO.StringIO() > > fig = Figure() > > canvas = FigureCanvasAgg(fig) > > ax = fig.add_subplot(111) > > ax.plot(range(5), range(5)) > > canvas.print_figure(output) > > start_response('200 OK', [('Content-type', 'image/png'), ('Content- > > Length', str(output.tell()))]) > > return [output.getvalue()] > > > -- > > You received this message because you are subscribed to the Google Groups > > "modwsgi" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group > > athttp://groups.google.com/group/modwsgi?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/modwsgi?hl=en.
-- You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
