[mod_python] Problems with PythonPath directive

Barry Warsaw barry at python.org
Tue Aug 26 14:29:31 EST 2003


FTR: Apache 2.0.47, mod_python 3.0.3, Python 2.3+LONG_LONG patch
(although I've also tried Python 2.2.3).

I'm having trouble with the PythonPath directive.  Mostly likely I don't
understand how it's supposed to work.  Here are my Apache directives:

LoadModule python_module /usr/local/apache/modules/mod_python.so
                                                                                
<Directory /path/to/project/xxx/xxx_apps>
    AddHandler python-program .py
    #PythonPath "sys.path + ['/path/to/project/zope2/lib/python']"
    PythonHandler regserver.driver
    PythonDebug On
</Directory>

ScriptAlias /regserver/ "/path/to/project/xxx/xxx_apps/"

When I hit http://localhost/regserver/driver.py with the PythonPath
directive commented out, everything works fine.  But when I uncomment
the PythonPath directive, I get an import error:

Mod_python error: "PythonHandler regserver.driver"

Traceback (most recent call last):

  File "/usr/local/lib/python2.3/site-packages/mod_python/apache.py", line 320, in HandlerDispatch
    module = import_module(module_name, config)

  File "/usr/local/lib/python2.3/site-packages/mod_python/apache.py", line 496, in import_module
    f, p, d = imp.find_module(parts[i], path)

ImportError: No module named regserver

I thought that the way I'm specifying PythonPath above should have added
to sys.path, not overwritten it.  What am I missing?

Thanks,
-Barry

P.S. there is a buglet in the online manual.  It says that --with-apxs
searches /usr/local/apache/bin but it really appears to search only
/usr/local/apache/sbin.  While my apxs lives in the former, I had to use
the --with-apxs configure option for it to find it.




More information about the Mod_python mailing list