[mod_python] Import Local Name Error, need help!

Jim Gallacher jpg at jgassociates.ca
Mon May 8 16:01:54 EDT 2006


Mohamed Sordo wrote:
> Hi everybody,
> I've some problems with my mod_python.
> I'm trying to execute server_side.py via mod_python.
> I have a mod_python_my_files.conf in /etc/apache2/conf.d/
> 
> It seems like that:
> 
> <IfModule mod_alias.c>
>    Alias /my_server /home/neomoha/PFC/src/server_side.py
> </IfModule>
> <DirectoryMatch /home/neomoha/PFC/src/ >
> 
> # mod_python 3.X
>    AddHandler mod_python .py
>    PythonHandler mod_python.publisher
>    PythonDebug On
> 
>    Options +FollowSymLinks
> 
>    Order allow,deny
>    Allow from all
> </DirectoryMatch>
> 
> NOTE: server-side.py is rwx for everybody
> 
> When a execute a python script that uses my localhost connection with
> mod_python , I have this output:
> 
> 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 "/home/neomoha/PFC/src/server_side.py", line 22, in ?
>    from myfile import MyFile
> 
> ImportError: cannot import name MyFile
> 
> NOTE: myfile.py is in /home/neomoha/PFC/src/ directory.
> And I'm using Apache/2.0.55 (Debian) mod_python/3.1.3 Python/2.3.5 
> Server at
> localhost Port 80

Either put myfile.py somewhere in your python path (eg. 
/usr/local/python2.3/site-packages/myfile.py) or add the path using 
PythonPath "['/path/to/myfile.py',] + sys.path" in your apache 
mod_python_my_files.conf file.

Note that it is considered to be bad practice to add any directories 
under your document root using PythonPath. You are likely to observe 
strange import behaviour.

Jim


More information about the Mod_python mailing list