I'm moving a web application from a Windows environment to CentOS 5.11 and Apache, and with everything installed, I'm receiving a 500
when I try to load up the site. The error log shows this:
mod_wsgi (pid=5461): Target WSGI script '/usr/local/treehouse/wsgi/index.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=5461): Exception occurred processing WSGI script '/usr/local/treehouse/wsgi/index.wsgi'.
Traceback (most recent call last):
File "/usr/local/treehouse/wsgi/index.wsgi", line 11, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named 'django.core.wsgi'
I found this question (and the related ones), which appears to be similar but none of the answers there fix the issue. I'm not running in a virtualenv
, and django appears to be installed correctly, as I can run the offending statement:
>>> from django.core.wsgi import get_wsgi_application
in the interactive Python interpreter and it works just fine. Here's the script causing the error (it's just the default index.wsgi
that you see everywhere you look for this stuff):
import os, sys
sys.path.append('/usr/local/treehouse/apple')
sys.path.append('/usr/local/treehouse/apple/apple')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "apple.settings")
from django.core.wsgi import get_wsgi_application application = get_wsgi_application()
Obviously the last line causes the error, but here's the fun part: the last line remains the problem, even if I add this just above it:
import django.core
import django.core.handlers
Both of the underlying packages import without a hitch (django.core.wsgi
is just a thin wrapper around some functionality in django.core.handlers.wsgi
). It's only when I try to access the wsgi
packages that problems occur. Inspecting sys.path
within this script shows all the right directories (/usr/local/lib/python3.4/site-packages
, etc.). And again, running the exact same code from the interactive interpreter causes no errors.
I tried an uninstall/reinstall of django (pip install django==1.6.5
), then I reset the VM to a totally clean snapshot and rebuilt/reinstalled everything, and still I get the exact same behavior.
What is going on?