[mod_python] how to use pythonImport ?

Graham Dumpleton graham.dumpleton at gmail.com
Mon Aug 4 19:05:43 EDT 2008

2008/8/4 bharath venkatesh <bharathv6.project at gmail.com>:
> hi all ,
>            I learn that pythonimport directory tells apache to import a
> module when apache starts so i tried to import a module by placing the
> pythonimport directive  in server configuration file .
> like this:
> PythonImport   /home/bharath/module.py    /usr/bin/python2.5

As I believe I asked you before, why are you specifying interpreter
name as '/usr/bin/python2.5'. This isn't meant to be a path to the
'python' executable, it is just a name which has meaning within
mod_python itself. If you are going to use PythonImport, you are
likely going to also need PythonInterpreter so you can force which
interpreter your application is run in. Otherwise, you have to work
out what interpreter your application is running in by default and use
that name with PythonImport. Have you application dump out value of
req.interpreter to work it out.

> this does not report any error when i restart the server  unless i specify
> wrong path to the module

If it doesn't report an error, isn't that good, it means it probably worked.

> but how to use the module imported by PythonImport module

What do you mean by use it? It is just a facility to preload a Python
module at process startup. Yes it can do work as a side effect by
having executable code at global scope in that module, but if that
code is something that can fail, you really need a way for a specific
request to retrigger same code if some initialisation not complete,
otherwise only way to recover is restart Apache again.

> if i do import module in my handler i can't get a import error saying that
> no module as such
> can anyone tell me how to use the module imported using pythonimport
> directive

Small, self contained code example of what you are doing would help.
The exact error messages from Apache error logs would also help. It is
hard to tell you how to do something if you haven't explained what you
have tried so far and are complaining doesn't work.

> and also if the module that is imported by pythonimport is changed will
> apache automatically reimport it ?

As directed in PythonImport documentation, read about import_module() in:


BTW, please ensure you reply-all to list and stop replying just to me.
I ignore such mails if people consistently do that.


More information about the Mod_python mailing list