I am trying to use Django for my next web project, and (thought) I had everything installed nicely, but I try to visit my site (a minimal new django project) and I get a 500 error.
My set up uses apache, mod_wsgi, and I'm using my mac for development.
Looking in the apache error logs, I see
ImportError: Could not import settings 'mysite.settings'
(Is it on sys.path? Is there an import error in the settings file?):
No module named mysite.settings
First, I double check which python mod_wsgi is using:
wpa072077:mysite enewe101$ otool -L /usr/local/Cellar/mod_wsgi/3.3/libexec/mod_wsgi.so
/usr/local/Cellar/mod_wsgi/3.3/libexec/mod_wsgi.so:
/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.21.0)
Ok, so i fire up that python and try importing mysite.settings -- It works with no problem, because I put it on my PYTHONPATH
.
Hmm, maybe mod_wsgi isn't getting my PYTHONPATH
? So I try adding this to my http.conf
inside the Virtual Host
section for my site:
SetEnv PYTHONPATH /Users/enewe101/projects/mysite/src
(The mysite module is at /Users/enewe101/projects/mysite/src/mysite
and it contains __init__.py
as it should)
One last thing: I have two versions of python on my machine. As I mentioned, I checked which one mod_wsgi was compiled against and if I enter the REPL for that one I can import mysite.settings
no problem. However, I actually wish mod_wsgi to use a different python -- but same version (both 2.7). I try forcing mod_wsgi to use my desired python by putting this in httpd.conf:
WSGIPythonHome /Library/Frameworks/EPD64.framework/Versions/7.3
WSGIPythonPath /Library/Frameworks/EPD64.framework/Versions/7.3/lib/python2.7/site-packages:/Library/Python/2.7/site-packages:/Users/enewe101/projects/mysite/src
but it causes the server to simply not respond -- my browser spins until I get impatient.
How can I resolve this import error, and preferably get mod_wsgi to use the correct python?
Related: