[mod_python] mod_python calls the wrong python executable

Graham Dumpleton grahamd at dscpl.com.au
Wed Jul 19 06:55:54 EDT 2006


On 19/07/2006, at 8:28 PM, mvanier wrote:

> OK, I figured it out thanks to your hint.  What I hadn't realized  
> (or had forgotten) is that apache has to run as root (at least  
> initially), and my compiled-from-source python wasn't in the root  
> path.  As it turned out, the root path includes /usr/local/bin so I  
> added a symlink to my python from there and everything works.  Woo  
> hoo!
>
> Would it be feasible to have a PythonExecutable httpd.conf  
> directive to deal with this problem more explicitly?  I'm still not  
> clear on how mod_python tells apache that it's supposed to be using  
> the "python" program to execute python code

Not necessarily that simple. The manner in which the Python libraries
determine where to look is quite complicated. See:

   Modules/getpath.c

in Python source code. Thus, although you could try and implement a
directive to tell it where to look, you have to get it to use your value
somehow. I haven't looked at it properly, but you may be able to have
the directive trigger the setting of the PYTHONHOME environment
variable to achieve it.

I have deferred trying to implement such a thing in the past as we  
weren't
able to understand what was happening. This was the point of adding the
extra debug output in new versions. Based on what we see from cases like
yours we can decide whether we do need such a directive as PythonHome
or equivalent.

Graham

> Mike
>
> Graham Dumpleton wrote:
>> On 19/07/2006, at 6:30 PM, mvanier wrote:
>>> I'm trying to run mod_python using the latest mod_python snapshot  
>>> with apache 2.2 (compiled from source) on Debian Linux.  I've run  
>>> into a strange error: when I try to run a python script through  
>>> the server, the wrong python executable gets called.  Here's the  
>>> apache error log:
>>>
>>> [Wed Jul 19 01:21:25 2006] [error] make_obcallback: could not  
>>> import mod_python.apache.\n
>>> ImportError: No module named mod_python.apache
>>> [Wed Jul 19 01:21:25 2006] [error] make_obcallback: Python path  
>>> being used "['/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/ 
>>> lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/ 
>>> lib/python2.4/lib-dynload', '/usr/local/lib/python2.4/site- 
>>> packages', '/usr/lib/python2.4/site-packages', '/usr/lib/ 
>>> python2.4/site-packages/PIL', '/var/lib/python-support/ 
>>> python2.4', '/usr/lib/site-python']".
>>> [Wed Jul 19 01:21:25 2006] [error] get_interpreter: no  
>>> interpreter callback found.
>>> [Wed Jul 19 01:21:25 2006] [error] [client 127.0.0.1]  
>>> python_handler: Can't get/create interpreter.
>>>
>>> The sys.path of this python interpreter is the one that would  
>>> exist if /usr/bin/python2.4 (which was installed by Debian) was  
>>> called instead of the correct one, which (in my case) is /usr/ 
>>> local/packages/python/bin/python (which I compiled and installed  
>>> myself from source).  I specified this executable when I  
>>> configured mod_python (using the --with-python option).  For some  
>>> reason, though, it isn't getting used.  Any ideas would be  
>>> appreciated.
>> At least you triggered the new debug output specifically put into  
>> mod_python
>> 3.2.9/3.3 to help debug this sort of problem.
>> Anyway, try ensuring that you have "/usr/local/paclages/python/ 
>> bin" first in the
>> PATH environment variable of the user that Apache is run as. If  
>> you don't and
>> when Python is initialised in the context of mod_python, it finds  
>> evidence first
>> of Python being installed in some other location instead of the  
>> one you want,
>> then it will setup sys.path based on the location of that other  
>> version of Python
>> and thus not look where you actually installed the Python  
>> components of
>> mod_python.
>> BTW, does /usr/bin/python or /usr/lib/python2.4 actually exist.
>> Graham



More information about the Mod_python mailing list