[mod_python] Setting the python executable

Evert Rol evert.rol at gmail.com
Fri Apr 11 04:14:42 EDT 2008

>> I'm having a hard time telling Apache (or mod_python) to tell which  
>> python
>> executable to use.
>> The thing is, I don't have a root access, so I'm running the Apache  
>> server
>> and python 2.5 under my user account. Both have also been installed  
>> this
>> way, ie, they are in my in the directory tree of my user account.
>> To avoid interference with the older system python (2.3), I just call
>> python with the full path (I try to avoid changing my path, since  
>> some of
>> these scripts run as cron jobs, bypassing a lot of setup files).
>> Bit of debugging (eg, print sys.executable in a mod_python script)  
>> showed,
>> however, that mod_python is still happily using the system python,  
>> not my
>> locally installed. That goes fine up to a certain point, but it  
>> does of
>> course crash in the end. I had compiled mod_python with the --with- 
>> python
>> and --with-apxs options, but looks like that doesn't help here.
>> After some further searching around, I came across the Action  
>> directive for
>> Apache; still didn't work, although that may be simply because I  
>> did that
>> incorrectly.
>> For the record, I'm using mod_python for Django, maing things  
>> potentially
>> more convoluted.
>> Here's what my latest attempt at getting this to work (still  
>> failing after
>> plenty of Apache restarts):
>> Action thepython-program /home/evert/sw/bin/python2.5
>> # Django directory
>> <Location "/testing/">
>>    SetHandler thepython-program
>>    PythonHandler django.core.handlers.modpython
>>    SetEnv DJANGO_SETTINGS_MODULE mysite.settings
>>    PythonDebug On
>> </Location>
>> I'm beginning to run out of ideas (& Google search terms). Does  
>> anyone have
>> any pointers?
> The mod_python module embeds the Python interpreter and so it can only
> use the version you compiled it against, Your attempts therefore to
> use Action are fruitless in that respect, but also because that isn't
> what the Action directive is for.
> Please clarify which version of mod_python you are using and which
> version of Python it was actually compiled against. If using
> mod_python 3.3.1 you should see warning/error messages in Apache error
> log on startup when the version of Python that it was compiled against
> was in a non standard location on path of Apache user and thus
> couldn't be found. This though would generally result in complete
> failure, yet you suggest it works for a bit and fails which suggests
> that mod_python isn't compiled against version of Python you want and
> it is your Python code which is incompatible with the version of
> Python that mod_python was compiled for.

It is 3.3.1, with Python 2.5; the system python at /usr/bin/python is  
2.3. I cannot recall having seen any warning messages in the logs on  
finding the incorrect Python version. And I have absolutely no idea  
why parts of it seemed to work, and then it decided to crash. Looks  
like that had to do with sqlite from within Python, so it could be  
running into sqlite library incompatibilities (I don't know if 2.5 &  
2.3 handle those differently; does 2.3 using the system library, while  
2.5 has it built-in and therefore uses a different version?).
I did manage to solve it with setting the PATH, which, as said, isn't  
my preferred option.

>  https://issues.apache.org/jira/browse/MODPYTHON-225

Yep, that pretty much sums it up. Both the problem I'm having and the  
solution I wanted to achieve (set Apache directive to pick up the  
correct Python, instead of setting PATH). Looks like I just hadn't put  
the right search terms into Google.
I guess I have to make do with it for now.


More information about the Mod_python mailing list