I am running Apache httpd 2.4.4 on a RedHat 5 machine. I am using Django and running through mod_wsgi. I have Python 2.4.3 installed in /usr/bin and Python 2.7.6 installed in /usr/local/bin and I want to use 2.7.6. I build the 2.7.6 from source and also built mod_wsgi-3.4.
I have created a virtualenv using 2.7.6 and from a command shell, python -V tells me it's using 2.7.6 (after doing a . virtpy/bin/activate
). Running import sys; sys.version
shows me 2.7.6 as well, and sys.executable
shows me /www/sqla/virtpy/bin/python
.
When I run it from httpd, I get problems loading libraries and when I look at sys.version
, I see 2.7.3. The weird thing is that sys.executable
still shows me /www/sqla/virtpy/bin/python
, exactly the same one as I see from the command shell.
Specifically, when python tries to load _socket, I see this error from httpd:
ImportError: /www/sqla/virtpy/lib/python2.7/lib-dynload/_socket.so: undefined symbol: _PyInt_AsInt
If I try to import _socket from a command shell, no problem. I have . /www/sqla/virtpy/bin/activate
in my /etc/sysconfig/httpd and have restarted Apache with that change.
How can the same executable give different versions of python? How can I convince it to use the right one?
Use the checks documented in the mod_wsgi documentation to validate that how your mod_wsgi was compiled is correct:
Ensure that when doing this check that LD_LIBRARY_PATH is not set. Provide the output from ldd.
Also indicate whether you also have any Python 2.7 installation under /usr in addition to the one under /usr/local and specifically whether there is a Python 2.7 shared library under /usr/lib anywhere.
If you have used WSGIPythonHome directive in Apache configuration, say what you have set it to.