[mod_python] frustrating problem importing packages with mod_python

Graham Dumpleton grahamd at dscpl.com.au
Thu May 26 17:55:35 EDT 2005


Where is the "steve" package located in relation to the directory
containing the handler? What is your Python sys.path set to? Are
you overriding "PythonPath" directive? Are you using a ".htaccess"
file to enable use of publisher or the main Apache configuration
file? If the latter, have you used the "Directory" directive or
the "Location" directive to surround the mod_python definitions?

Try and answer these questions. Also post what the part of your
Apache configuration looks like where you enable use of publisher
for mod_python.

One warning, if you use "Location" in the Apache configuration
instead of "Directory", mod_python will not be able to add to the
Python module search path the physical directory for which the
PythonHandler directive is defined, ie., where your handler
potentially resides. As such, if your "steve" package is in a
subdirectory of your handler it will not be able to find it.
Further, even if "Directory" is used, if both the handler and
the "steve" package are in a subdirectory of the directory for
which PythonHandler is defined, it will not find "steve" as only
the top most PythonHandler directory is added to the module search
path.

Anyway, explain better how your directories are laid out etc
and then we might be able to be more specific.

Graham


On 27/05/2005, at 7:08 AM, Stephen Potenza wrote:

> I setup a simple mod_python publisher and it's working perfectly.
>
> [index.py]
> def index():
>     return "hi from index"
>
> When I access it through http://localhost/python/, I see "hi from
> index"... everything works fine.
>
>
> However, when I try import a module from a package I created named
> "steve", I get the following error:
>
> -------------------------------------------------------------------
> Mod_python error: "PythonHandler mod_python.publisher"
>
> Traceback (most recent call last):
>
>   File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
> 299, in HandlerDispatch
>     result = object(req)
>
>   File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
> 98, in handler
>     path=[path])
>
>   File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
> 457, in import_module
>     module = imp.load_module(mname, f, p, d)
>
>   File "/var/www/python/index.py", line 1, in ?
>     from steve import dummy
>
> ImportError: No module named steve
> -------------------------------------------------------------------
>
> [index.py]
> from steve import dummy
>
> def index():
>     return dummy.say()
>
> if __name__ == "__main__":
>     print index()
>
>
> The "steve" package/directory contains two files:
>
> - __init__.py (blank)
> - dummy.py
>
> [dummy.py]
> def say():
>     return "this is dummy!"
>
> When I run index.py from the command line, it works perfectly. Any 
> ideas??
>
> Thanks,
> Steve
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list