[mod_python] can't import python scripts into my index.py file

Graham Dumpleton graham.dumpleton at gmail.com
Sat Feb 28 23:45:12 EST 2009

2009/3/1 Ron Phelps <rphelps at redshift.com>:
> I have similar mod_python setups at work and home. The differences are
> at work the setup is Ubuntu Gutsy and at home I have Ubuntu Feisty so
> the home installation uses 3.2 mod_python and the work 3.3. The other
> difference is at home I have apache2 configured for two virtual
> websites. The work installation is only one website.
> The problem is I can't import python scripts from index.py on my home
> installation but I have no problem at work. Scripts in both
> installations are in the home directory of the website.
> -------------------
> Code example from work, index.py uses a href link to call the following
> python script all imports work eps_extract is python script in the same
> directory as index.py
> from cgi import escape
> from urllib import unquote
> #Import database and plotting functions
> from select import select
> import eps_extract
> def frame():
>        s = """\
>        ...
>        html code here
>        ..."""
>    return s
> def plots():
>        etc ...
> ------------------------
> Code example from home - index.py:
> I have tried simply using the import statement as above
> and like below. The scripts weatherstation and pexpect are in the same
> directory as index.py
> import sys, os
> from mod_python import apache
> weatherstation = apache.import_module("weatherstation")
> pexpect  = apache.import_module("pexpect")
> Mod_python returns
> ImportError: No module named weatherstation
> Thanks for any help you can give.

Simple, upgrade your home machine so it matches the latest version of
mod_python (3.3.1) used at work.

The module importer has lots of problems in the older version and you
really do not want to use it.

Once you have upgraded and use same version on both, then read the
documentation. Specifically that for import_module() in:




More information about the Mod_python mailing list