[mod_python] importing from package under mod_python.publisher

Sergiy Kuzmenko s.kuzmenko at gmail.com
Sun Apr 13 21:54:36 EDT 2008


Hi everybody,

Question about importing from package under mod_python.publisher.

Consider the following directory structure:

py
    foo
        __init__.py
        bar.py
    boo.py
    test.py

Let's say we have the following in test.py:

 import boo
 import foo.bar

When running test.py from command line this works fine. However, under
mod_python only "import boo" works and importing from a subdirectory
via "import foo.bar" produces ImportError: No module named foo.

This seems to be a deviation form the standard python's behaviour.

What is even more confusing that mod_python manual
(http://modpython.org/live/current/doc-html/tut-what-it-do.html)
states the following when describing the PythonHandler directive: "If
not already done, prepend the directory in which the PythonHandler
directive was found to sys.path".

When inspecting sys.path from a publisher defined like this:

<Directory /path/to/the/webroot/py>
 AddHandler mod_python .py
 PythonHandler publisher
 PythonDebug On
</Directory>

/path/to/the/webroot/py is actually not the system path!

Thanks
Sergiy


More information about the Mod_python mailing list