Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Problem calling python modules from python apache handler

Reply
Thread Tools

Problem calling python modules from python apache handler

 
 
mannewalis
Guest
Posts: n/a
 
      10-16-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
}

 
Reply With Quote
 
 
 
 
Graham Dumpleton
Guest
Posts: n/a
 
      10-16-2007
On Oct 17, 8:00 am, mannewalis <(E-Mail Removed)> wrote:
> 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


First, done call your package directory 'test'. There is a module in
Python called that and if it finds the Python module first it will not
find your package.

Second, you can't dump Python packages in the same directory as your
mod_python handler code file, they will not be found. Place them
outside of the Apache document tree and use PythonPath directive as
described in documentation to indicate where they are located.

Also ensure you read documentation for import_module() in:

http://www.modpython.org/live/curren...pi-apmeth.html

This covers issues around module loading in mod_python.

Graham


> 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
>
> }



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache Tomcat5.5 clustering problem with Apache HTTP server 2.2.4 tanmoy.b81 Java 0 02-04-2009 08:46 AM
Python Apache Handler Scooter Python 2 01-09-2009 08:31 PM
Configuring apache to execute python scripts using mod_python handler joe jacob Python 3 08-14-2007 03:27 AM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM



Advertisments