[mod_python] ImportError: No module named linecache

Graham Dumpleton graham.dumpleton at gmail.com
Sun Jun 24 22:35:12 EDT 2007


On 25/06/07, Marty Alchin <gulopine at gamemusic.org> wrote:
> On 6/24/07, Graham Dumpleton <graham.dumpleton at gmail.com> wrote:
> >   https://issues.apache.org/jira/browse/MODPYTHON-225
>
> It looks like that's mostly for situations where mod_python is being
> run in a different version of Python than it was compiled for, is that
> right?

No as you can't run it with a different version than what it was
compiled for. At least not a different major/minor version number.

It relates to where Python is installed in non standard location like
/usr/local/bin but python found in path of Apache is in /usr/bin.

> If that's the case, how can I tell which one mod_python was
> compiled against?

If you have compile from source and wanted to use something other than
the default, you should have used --with-python option to configure.

> As for specifying PATH directly for Apache, I tried the following, and
> it didn't seem to make a difference, but if mod_python was compiled
> against the wrong Python, I expect this wouldn't make any difference.
>
> # env PATH=/usr/local/lib/python2.4:$PATH /usr/local/apache2/bin/httpd -k start

Use:

  env PATH=/usr/local/bin:$PATH /usr/local/apache2/bin/httpd -k start

You need to add bin directory not lib directory to PATH.

> > Also run the command line python executable for the version you expect
> > to be able to use and go:
> >
> >   import mod_python
>
> # sudo -u apache python
> Python 2.4.3 (#1, May 12 2007, 21:38:42)
> [GCC 3.4.6 20060404 (Red Hat 3.4.6-3)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import mod_python
> >>>
>
> That's the preferred user, as well as the preferred version of Python,
> and it imports just fine. Of course, "from mod_python import apache"
> fails, but with the expected _apache ImportError, so that seems fine.

What about linecache. Forgot to ask that.

Is it possible that that module (.py or .pyc)  in Python installation
is not readable to the Apache user.

> Might I have to recompile mod_python and specify the intended Python
> installation?

If you didn't explicitly compile it for the version you want to be
used then perhaps. Use --with-python option as mentioned before.

PS, please use reply-all to keep discussion on list.

Graham


More information about the Mod_python mailing list