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

Graham Dumpleton graham.dumpleton at gmail.com
Tue Jul 28 00:32:38 EDT 2009


2009/7/28 Marc Weber <marco-oweber at gmx.de>:
> Hi Graham,
>
> mod_python looks in:
>  '$PYTHON_INSALL_LOCATION/lib/python25.zip'
>  '$PYTHON_INSALL_LOCATION/lib/python2.5'
>  '$PYTHON_INSALL_LOCATION/lib/python2.5/plat-linux2'
>  '$PYTHON_INSALL_LOCATION/lib/python2.5/lib-tk'
>  '$PYTHON_INSALL_LOCATION/lib/python2.5/lib-dynload'
>  '$PYTHON_INSALL_LOCATION/lib/python2.5/site-packages'
> It only contains default paths of the python installation.
>
> mod_python has been installed to:
>
>  $PACKAGE_DIR/nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python2.5/site-packages/mod_python/*
>  $PACKAGE_DIR/modules/mod_python.so
>
> PACKAGE_DIR            = /nix/store/ax9qlhyfjlsnc9lxa3p80gy1qsrjpn2m-apache-httpd-mod-python-3.3.1
> PYTHON_INSALL_LOCATION = /nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4

So mod_python Python modules are installed in:

  /nix/store/ax9qlhyfjlsnc9lxa3p80gy1qsrjpn2m-apache-httpd-mod-python-3.3.1//nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python2.5/site-packages/mod_python/*

Are you sure you got things right?

> both are different. Goto www.nixos.org to read up more details about
> this packaging scheme if you're interested.
>
>> /nix/store/axq79wn5py4sfi2n142jfc4arvgyr957-python-2.5.4/lib/python2.5/site-packages
>> unless the Python installation has been mightily fiddled with as well.
> Yes, I did so to make it install into its own directory. After python
> has been build no other build process is allowed to write into
> $PYTHON_INSALL_LOCATION for purity reasons.
>
>> You can't use SetEnv to control environment variables that Python
>> might be able to use at initialisation time.
> So can I do PYTHONPATH=foo $RUN_APACHE instead? I'll try.

No.

Depending on mod_python will even work doing it this way, can only
suggest you use 'virtualenv' to create a Python virtual environment in
your own writable space.

Then when you build mod_python use --with-python option to configure
to point at the Python in the virtual environment.

When installed, this should install mod_python stuff in virtual environment.

To get Apache/mod_python to then use this virtual environment at run
time however, you need to be able to set PYTHONHOME in environment of
Apache. Unless you are going to run 'httpd' by hand all the time,
can't usually do that.

If the Apache installation follows a standard ASF install structure,
there should be a 'envvars' file in  the same directory as 'httpd'
executable. PYTHONHOME should be set and exported in that. If however
that is in non writable directory as well, then you are stuffed and
likely cannot do it easily with your mod_python installation.

In mod_wsgi you wouldn't need to use 'envvars' as can set
WSGIPythonHome directive in Apache configuration file instead. Even
then, wouldn't be needed normally as you could just use standard
Python installation. Although in your case, since you can't install
other modules into standard site-packages, virtual environments with
mod_wsgi can still be useful. See:

  http://code.google.com/p/modwsgi/wiki/VirtualEnvironments

Personally I would suggest using a sane Linux distribution such as Ubuntu.

Graham



More information about the Mod_python mailing list