tags:

views:

107

answers:

1

Using CentOS5, I have Apache configured with the following directives.

Alias /pscript/ /var/www/pscript/
<Directory "/var/www/pscript/">
    Options +ExecCGI
    DirectoryIndex thetest.py
    AddHandler cgi-script .py
</Directory>

When I call www.domain.com/pscript/ then my python script runs and prints out my sys.path, which is displaying python2.4.

When I call a different script that requires Python 2.5, I get a 500 Internal Server Error.

Looking at my Apache error_log, I see the following line:

[Wed Mar 03 16:58:44 2010] [error] [client 000.000.000.000] Please use Python 2.5 or greater

From the command line, running python -V returns Python 2.5.5. I have both 2.4 and 2.5.5 installed, but only 2.5.5 should be in use.

In an attempt to remedy the Apache problem I recompiled Python 2.5.5 to be safe, and made sure to enable shared library. Then I recompiled mod_python in case that was affecting something, but my sys.path is still python2.4.

I wonder, do I need to recompile Apache 2.2.3 itself? I simply need Apache to utilize Python 2.5.5.

Thanks in advance.

+2  A: 

Does the Python script have a first line something like:

#!/usr/bin/python

If so, maybe /usr/bin/python is Python version 2.4, while running python directly from the command line is running a different Python executable (version 2.5) from somewhere else in your path. Try:

which python

to see what executable is being run when you run python from the command line.

Craig McQueen
From the command line I get /usr/local/bin/python, which is the Python 2.5.5 installation.
Structure
Does your Python script have `#!/usr/local/bin/python` at the top, or something else?
Craig McQueen
That was it. The script was calling /usr/bin/env to call python. It must have been calling the wrong one. I've updated my script to `#!/usr/local/bin/python` and printing my `sys.path` now shows it is utilizing the correct version. Thank you!
Structure
Excellent. Good to hear it's working.
Craig McQueen