[mod_python] problem importing numarray

Graham Dumpleton grahamd at dscpl.com.au
Mon Oct 24 23:27:46 EDT 2005


The sys.argv array isn't usually available when Python interpreters are
being embedded into a C/C++ program as is the case with mod_python.

I would suggest it is bad for a package to always assume that it will only
ever be used from standard "python" program exclusively.

A quick hack you can use to get around the problem is:

  import sys
  sys.argv = [ "mod_python" ]
  import numarray

This issue with sys.argv has come up before recently. Was thinking at
the time whether mod_python when initialised should setup a bodgy
sys.argv to avoid these problems.

Graham

Patrik Jonsson wrote ..
> hi,
> 
> I just started playing with mod_python and I have a problem importing
> the numarray module. it works fine from the command line, but not when
> executed through mod_python.  I have the Publisher handler and a very
> basic script:
> 
> "
> import numarray
> "
> 
> This gives the following output:
> 
> Mod_python error: "PythonHandler mod_python.publisher"
> 
> Traceback (most recent call last):
> 
>   File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line
> 299, in HandlerDispatch
>     result = object(req)
> 
>   File "/usr/lib64/python2.4/site-packages/mod_python/publisher.py",
> line 98, in handler
>     path=[path])
> 
>   File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line
> 457, in import_module
>     module = imp.load_module(mname, f, p, d)
> 
>   File "/home/www/patrik/simulations/junk.py", line 1, in ?
>     import numarray
> 
>   File "/usr/lib64/python2.4/site-packages/numarray/__init__.py", line
> 42, in ?
>     from numarrayall import *
> 
>   File "/usr/lib64/python2.4/site-packages/numarray/numarrayall.py",
> line 1, in ?
>     from numerictypes import *
> 
>   File "/usr/lib64/python2.4/site-packages/numarray/numerictypes.py",
> line 390, in ?
>     from codegenerator.ufunccode import typecode
> 
>   File
> "/usr/lib64/python2.4/site-packages/numarray/codegenerator/__init__.py",
> line 1, in ?
>     from basecode import all_types
> 
>   File
> "/usr/lib64/python2.4/site-packages/numarray/codegenerator/basecode.py",
> line 20, in ?
>     if hasUInt64():
> 
>   File
> "/usr/lib64/python2.4/site-packages/numarray/codegenerator/basecode.py",
> line 11, in hasUInt64
>     return "--hasUInt64" in sys.argv
> 
> AttributeError: 'module' object has no attribute 'argv'
> 
> 
> 
> 
> This looks like sys.argv doesn't exist from within mod_python?  I agree
> this information probably isn't useful in this context, but since all
> documentation I've seen says that sys.argv is defined, it seems bad to
> break existing software that relies on its existence. Shouldn't it just
> be [''] like it is when you run the interpreter from the command line?
> 
> Incidentally, if I reload the page, I get instead:
> 
> Mod_python error: "PythonHandler mod_python.publisher"
> 
> Traceback (most recent call last):
> 
>   File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line
> 299, in HandlerDispatch
>     result = object(req)
> 
>   File "/usr/lib64/python2.4/site-packages/mod_python/publisher.py",
> line 98, in handler
>     path=[path])
> 
>   File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line
> 457, in import_module
>     module = imp.load_module(mname, f, p, d)
> 
>   File "/home/www/patrik/simulations/junk.py", line 1, in ?
>     import numarray
> 
>   File "/usr/lib64/python2.4/site-packages/numarray/__init__.py", line
> 42, in ?
>     from numarrayall import *
> 
>   File "/usr/lib64/python2.4/site-packages/numarray/numarrayall.py",
> line 1, in ?
>     from numerictypes import *
> 
>   File "/usr/lib64/python2.4/site-packages/numarray/numerictypes.py",
> line 168, in ?
>     Byte = _register("Byte",   Int8)
> 
>   File "/usr/lib64/python2.4/site-packages/numarray/numerictypes.py",
> line 68, in _register
>     raise ValueError("Type %s has already been registered" % name)
> 
> ValueError: Type Byte has already been registered
> 
> 
> 
> If anyone has any ideas on how to fix this, I'd much appreciate it!
> 
> Thanks,
> 
> /Patrik


More information about the Mod_python mailing list