Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

Edit: It appears both of my python installations have shared libraries. Obviously the 2.4 version predates 2.5. Would this be a possible cause?

Thanks in advance.

share|improve this question
    
Found a solution for this? I'm facing this same issue. –  SHOUBHIK BOSE Aug 27 '13 at 15:08

2 Answers 2

The apache process is most likely running as a different user and might be picking up a different system path to your own user.

Perhaps, assuming your apache user is www-data, running the following command will confirm it:

sudo su www-data python -V
share|improve this answer
    
The user is different, I confirmed the one that was declared in the httpd.conf file. Using "su" to login as that user, I ran "python -V" and it printed "Python 2.5.5" –  Structure Mar 3 '10 at 9:23
up vote 0 down vote accepted

Within my python script /usr/bin/env was being used to call Python. This was calling the wrong version. Not sure how to make it call a different version, but changing my scripts to /usr/bin/local/python (Python 2.5.5 installation) corrected the problem.

share|improve this answer
    
You'd set/adjust the sys.path environment variable (for the user the script runs as) to pick up your desired Python version. Alternatively, you could take a look at virtualenv. –  dwightgunning Mar 4 '10 at 10:13
    
Is there a preferred way to modify sys.path to accomplish this? I will also look into virtualenv. –  Structure Mar 5 '10 at 1:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.