[mod_python] problem to import pylab of matplotlib

Graham Dumpleton grahamd at dscpl.com.au
Fri May 27 08:01:31 EDT 2005


On 27/05/2005, at 9:38 PM, Damien wrote:
> the content of /usr/lib/python2.3/site-packages/pylab.py is :
>
> from matplotlib.pylab import *
>
>
> If y replace the "import pylab" by "from matplotlib.pylab import *" in 
> my index.py
> i have a new error  :
>
> pylab function
> <pre>
> Mod_python error: "PythonHandler index"
>
> Traceback (most recent call last):
>
>  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 
> 299, in HandlerDispatch
>    result = object(req)
>
>  File "/var/www/html/index.py", line 15, in handler
>    for i in dir(pylab):
>
> NameError: global name 'pylab' is not defined
>
> </pre>

You would need to use:

   for in globals().keys():

instead of:

   for i in dir(pylab):

as using "from matplotlib.pylab import *" imports them into your own
globals.

This means that instead of:

   pylab.figure(1)

you would also just use:

   figure(1)

Anyway, the original pylib.py should have worked as standard Python
import is being used.

One possibility for problems is that everything is contained in .so 
files.
There may be some sort of problem loading these within the context of 
the
Apache process. I would though have expected to see a Python exception
if there was.

Only thing I can think of is to stop and start Apache and then look in
the Apache error log file. There may be errors which are getting sent
to stderr but which aren't getting flushed immediately (known issue).
By shutting down Apache these error messages usually then get flushed
and can be seen.

Graham



More information about the Mod_python mailing list