[mod_python] how to configure sys.path when installing not into python's lib directory?

Marc Weber marco-oweber at gmx.de
Mon Jul 27 21:24:09 EDT 2009


I'd lite to play with mod_python. I'm running nixos using the nix
package manager. It's special because every package is installed into
its own package diroctory by default.

It compiles fine but of course the import path is not correct then:

  [Tue Jul 28 00:59:43 2009] [error] make_obcallback: could not import mod_python.apache.\n
  ImportError: No module named mod_python.apache
  [Tue Jul 28 00:59:43 2009] [error] make_obcallback: Python path being used "['/nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python25.zip', '/nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python2.5', '/nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python2.5/plat-linux2', '/nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python2.5/lib-tk', '/nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python2.5/lib-dynload', '/nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python2.5/site-packages']".

I read from docs that I can use

  PythonOption mod_python.importer.path "['path']"

but this didn't work? Is it added after the lines
    m = PyImport_ImportModule("mod_python.apache");
are executed (mod_python.c)

The README also contains a hint:

  - Running your own version of mod_python without installing it is possible and 
  useful if you cannot be root, but you're a bit on your own, sorry. You'll have 
  to make sure MOD_PYTHON/testconf.py points to the right version of 
  mod_python.so and tweak Apache user's PYTHONPATH environment variable so that
  mod_python can find its Python modules.

What is the Apache user's PYTHONPATH environment variable?
I tried adding to my apache config:
  SetEnv PYTHONPATH $PACKAGE_DIR/nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python2.5/site-packages

A php test "echo getenv('PYTHONPATH');" showed that the var got assigned.
Still the path isn't added to the import list.

Is there something else I can try?

Of course I can patch the python install receipt making it install
mod_python as well. However that's suboptimal.

Can I automatically patch the .c code to add that module directory?

Marc Weber

More information about the Mod_python mailing list