[mod_python] Troubles with including local modules

Pavel Roitberg pavel at madman2k.net
Tue May 30 09:48:45 EDT 2006


Jim Gallacher wrote:
> Pavel Roitberg wrote:
>> Hi,
>>
>> I'm trying to dig into python using mod_python, but I already fail with
>> this easy thing.
>> I can include modules located in /usr/lib without problems, but when I
>> try to include a local module I'm getting the following error:
>>
>> """
>> Mod_python error: "PythonHandler index"
>>
>> Traceback (most recent call last):
>>
>>   File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
>> 287, in HandlerDispatch
>>     log=debug)
>>
>>   File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line
>> 457, in import_module
>>     module = imp.load_module(mname, f, p, d)
>>
>>   File "/home/pavel/data/webwork/python/index.py", line 3, in ?
>>     from module import article
>>
>> ImportError: cannot import name article
>> """
>>
>> It only works after python generates the according pyc files. (when I
>> import them manually using the interpreter)
>>
>> Apache.import_module() does not work at all; neither error, nor module
>> in local namespace.
>>
>> The environment is:
>> mod_python 3.1.4
>> apache 2.0.55-4ubuntu2
>> python 2.4.2-0ubuntu3
>> Ubuntu 6.06
>>
> 
> It's not clear to my why it works for pyc files, but not py files. 
> Perhaps you could include your mod_python apache configuration 
> (AddHandler, etc), and a code snippet.
> 
> Jim
sure

Apache Config:
<Directory /home/pavel/data/webwork/python>
	Options Indexes FollowSymLinks
	AllowOverride FileInfo
	SetHandler mod_python
	PythonHandler index
	PythonDebug On
	Order allow,deny
	allow from all
</Directory>

index.py:
from mod_python import apache, psp, Cookie
import time, sys
from module import article

bla = dir()

def handler(req):	
	content = req.uri[1:].split("/")+bla
		
	req.content_type = "application/xhtml+xml"
	
	template = psp.PSP(req, 'template/main.xhtml')
	template.run({"title":"News", "user":"Pavel", "content":content, 
"pages":3, "active":1})

	return apache.OK



More information about the Mod_python mailing list