[mod_python] mod_python claims it cannot find a module

Martin MOKREJŠ mmokrejs at ribosome.natur.cuni.cz
Tue Jul 5 08:57:14 EDT 2005


Nicolas Lehuen wrote:
> Martin,
> 
> From what I see in your source code, you should request for :
> 
> http://aquarius/~mmokrejs/conference/index_conference.py<http://aquarius/%7Emmokrejs/conference/index.py>
> 
> and not :
> 
> http://aquarius/~mmokrejs/conference/index.py<http://aquarius/%7Emmokrejs/conference/index.py>
> 
> Because you commented out the Index directive in the .htaccess. Do you still 
> have the problem when fixing this ? FYI, I have installed your source code 

Umm, no, you are right, I was too fast when doing this today. sorry for noise.

> on my machine, and everything is OK except for the various import problems 
> that have to be sorted otherwise. For instance, I've added :
> 
> PythonPath sys.path+["/path/to/conference"]
> 
> to the .htaccess file and now sql_io is correctly found.
> 
> To me, apart from the annoying import issues that can worked around (until 

I have just reproduced the "file() constructor not accessible in restricted mode" error.
More in a separate thread.

> we have a nice solution), everything is working OK.

Well, I have used the apache.import functions as Graham proposed yesterday. The code
looks like this at the moment in file where I import my own modules and works:


#! /usr/bin/env python

# $Id:

# import system-wide modules as they are in the PYTHON_PATH
import os

# import our modules but do not depend on PYTHON_PATH
# When we get executed under mod_python, the cuurent
# directory is not in PYTHON_PATH _if_ PythonHandler
# was not defined under "Directory" directive in httpd.conf
# or within .htaccess. But that still doesn't help
# with modules located in subdirectories - those are
# not in PYTHON_PATH even in "Directory" case!
# So, workaround that too here.
# http://www.modpython.org/pipermail/mod_python/2005-July/018588.html

try:
    from mod_python import apache

    _directory = os.path.dirname(__file__)
    for _my_modulename in ['web_settings', 'web_header', 'web_menu', 'web_text_frame', 'web_footer', 'sql_io', 'helper_functions']:
        __dict__[_my_modulename] = apache.import_module(_my_modulename, path=[_directory])
except:
    import web_settings
    import web_header
    import web_menu
    import web_text_frame
    import web_footer
    import sql_io
    import helper_functions


[cut]



More information about the Mod_python mailing list