Python – Apache showing “Python version mismatch” with mod_wsgi

apache-2.2centos5mod-wsgipython

I am trying to get web.py working.

I have compiled mod_wsgi to use python2.6, and configured my virtualhost correctly (at least I am pretty sure it is!). The hello, world application keeps showing up as 404. I changed the loglevel of Apache to info. and am seeing the following:

[Wed Sep 28 15:41:12 2011] [info] mod_wsgi (pid=25969): Attach interpreter ''.
[Wed Sep 28 15:42:55 2011] [info] mod_wsgi (pid=25969): Create interpreter 'clearpoint.turnleftllc.com|/budgetcalculator'.
[Wed Sep 28 15:45:33 2011] [info] mod_wsgi (pid=25969): Destroying interpreters.
[Wed Sep 28 15:45:33 2011] [info] mod_wsgi (pid=25969): Destroy interpreter 'clearpoint.turnleftllc.com|/budgetcalculator'.
[Wed Sep 28 15:45:33 2011] [info] mod_wsgi (pid=25969): Cleanup interpreter ''.
[Wed Sep 28 15:45:33 2011] [info] mod_wsgi (pid=25969): Terminating Python.
[Wed Sep 28 15:45:33 2011] [error] Exception KeyError: KeyError(-1216178416,) in <module 'threading' from '/usr/lib/python2.6/threading.pyc'> ignored
[Wed Sep 28 15:45:33 2011] [info] mod_wsgi (pid=25969): Python has shutdown.
Fatal Python error: Interpreter not initialized (version mismatch?)

Regarding the KeyError, I am really not sure where that is coming from. I tested the application from the command line (python26 code.py) and it executes without error. It gives no output whatsoever in fact.

Just in case, here is my VirtualHost configuration, as well as the application code:

Python Code (taken directly from the web.py site):

#!/usr/bin/python26
import web

urls = (
        '/.*', 'index'
        )

class index:
    def GET(self):
        return "Hello, world!"


app = web.application(urls,globals()).wsgifunc()

VirtualHost:

<VirtualHost xxx.xxx.xxx.xxx:80>
        ServerAdmin "tom@turnleftllc.com"
        ServerName clearpoint.turnleftllc.com
        ServerAlias clearpoint
        ErrorLog logs/clearpoint_error_log

        DocumentRoot /home/turnleftllc/public_html/cpccs
        WSGIScriptAlias /budgetCalculator /home/turnleftllc/public_html/cpccs/apps/code.py
        Alias /budgetCalculator/static /home/turnleftllc/public_html/cpccs/apps/static
        AddType text/html .py
        <Directory /home/turnleftllc/public_html/cpccs>
                Order allow,deny
                Allow from all
                AllowOverride All
        </Directory>
        <Directory /home/turnleftllc/public_html/cpccs/apps>
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>

I am using CentOS5, which defaults to python2.4. I did uninstall and recompile mod_wsgi for python2.6 (as you can see in the output, it's definitely initializing 2.6).

Any help would be greatly appreciated!

Best Answer

Make sure you aren't still loading mod_python into same Apache.

Read the following and validate your installation.

http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Installation_In_Use

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

The KeyError message is because you are using old mod_wsgi version and not the latest so if you built from source code make sure you used mod_wsgi 3.3.