Problem calling python modules from python apache handler

mannewalis justinagraham at gmail.com
Tue Oct 16 18:00:48 EDT 2007


Hi,

I have the following setup...

Apache 2.2.3, Python 2.5 and mod_python 3.3.1

I have configured apache to call a python script when fetching .py
resources...so far so good... I did the hello world script in the
mod_python docs and it works great.

Now when I want to add some meat and potatoes and call some other
python code from the script things get pear shaped.. I try to import
the module I want, but it never can find it... I always get the
error...

ImportError: No module named ???

no matter what I do. I have moved my python modules around, to no
avail. I've even put them in the same directory as the handler script
and even that doesn't work.

I am fairly new to python, so I expect there is some search-path-
fu(tm) that I am presently unaware of. Can anybody explain how to get
this working?

Thanks
Justin



For example...

I have the following folders...

\python25\lib\test\

with the script mytest.py

In my apache hander I try to import this script

from test import mytest

and get the error..


MOD_PYTHON ERROR

ProcessId:      4988
Interpreter:    'localhost'

ServerName:     'localhost'
DocumentRoot:   'C:/Program Files/EasyPHP 2.0b1/www'

URI:            '/foo.py'
Location:       None
Directory:      'C:/Program Files/EasyPHP 2.0b1/www/'
Filename:       'C:/Program Files/EasyPHP 2.0b1/www/foo.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'query'

Traceback (most recent call last):

  File "C:\Python25\lib\site-packages\mod_python\importer.py", line
1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "C:\Python25\lib\site-packages\mod_python\importer.py", line
1202, in _process_target
    module = import_module(module_name, path=path)

  File "C:\Python25\lib\site-packages\mod_python\importer.py", line
296, in import_module
    log, import_path)

  File "C:\Python25\lib\site-packages\mod_python\importer.py", line
680, in import_module
    execfile(file, module.__dict__)

  File "C:\Program Files\EasyPHP 2.0b1\www\query.py", line 2, in
<module>
    from test import mytest

ImportError: No module named test


MODULE CACHE DETAILS

Accessed:       Tue Oct 16 14:50:22 2007
Generation:     4

_mp_9bae44ea3d2a76746732f5d982e3e12d {
  FileName:     'C:\\Program Files\\EasyPHP 2.0b1\\www\\query.py'
  Instance:     13 [RELOAD]
  Generation:   4 [ERROR]
  Modified:     Mon Oct 15 19:54:19 2007
  Imported:     Mon Oct 15 19:50:44 2007
}




More information about the Python-list mailing list