Error while configuring Django with mod_wsgi in Python inside Anaconda: "ImportError: No module named django.core.wsgi"
I have few problems running django + apache2 on ubuntu. Django 1.7, Apache2.4.7
I am running an anaconda stack with 3.4 as main + other environment on python 2
I was trying to set up a simple test site and got an internal 500 error, with the following error messages in the Apache error log:
[Sat Jan 10 11:56:16.095032 2015] [:error] [pid 14441:tid 140015774267136] [client 127.0.0.1:59135] ImportError: No module named django.core.wsgi
[Sat Jan 10 12:03:01.895432 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] mod_wsgi (pid=14439): Target WSGI script '/PATH/mysite/wsgi.py' cannot be loaded as Python module.
[Sat Jan 10 12:03:01.895483 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] mod_wsgi (pid=14439): Exception occurred processing WSGI script '/PATH/mysite/wsgi.py'.
[Sat Jan 10 12:03:01.895498 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] Traceback (most recent call last):
[Sat Jan 10 12:03:01.895515 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] File "/PATH/mysite/wsgi.py", line 13, in <module>
[Sat Jan 10 12:03:01.895565 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] from django.core.wsgi import get_wsgi_application
[Sat Jan 10 12:03:01.895582 2015] [:error] [pid 14439:tid 140015774267136] [client 127.0.0.1:59157] ImportError: No module named django.core.wsgi
wsgi.py:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
its launch is done with
python manage.py runserver
So the problem here is (I think) mod-wsgi was not configured on the correct python since python is by default ("mod_wsgi / 3.4 Python / 2.7.6 configured") and django is installed on anaconda 2.7.9 one.
If my guess is good (please let me know what other info we need for the soul) My question is, how do I recompile mod-wsgi so it is linked to the 2.7.9 environment from anaconda? Another question: can I leave it as it is and just add some directive to link to the anaconda libraries? What folder would it be, and where would I put the WSGIPythonHome directive?
Thanks for watching
source to share
Had a similar problem, the answer was in the virtual host file:
WSGIDaemonProcess mysite python-path=/path/to/mysite:/path/to/anaconda3/envs/python2/lib/python2.7/site-packages/
WSGIProcessGroup mysite
WSGIScriptAlias / /path/to/mysite/mysite/wsgi.py
ServerName www.mysite.com
ServerAlias mysite.com
ServerAdmin webmaster@mysite.com
<Directory /path/to/mysite/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog /path/to/web/test/error.log
source to share
Check this setting in httpd.conf
your Apache:
Under <VirtualHost x:y>
make sure the value python-path
in WSGIDaemonProcess
includes the Python sites directory in your Anaconda installation .
Otherwise mod_wsgi may not find the Django you installed for Python inside Anaconda .
For example, if you installed Anaconda for:
/opt/anaconda2
Python site packages directory could be:
/opt/anaconda2/lib/python2.7/site-packages
So change WSGIDaemonProcess
like: WSGIDaemonProcess YOUR_PROJECT_NAME python-path=/opt/anaconda2/lib/python2.7/site-packages:YOUR_PROJECT_DIRECTORY ......
(Separate each path with colon :
)
Note:
1. The version number inside the path may change according to the version of your instrument. ... Find a similar path and try.
2. This problem can occur in every Linux distribution (not only Ubuntu), but even Windows.
source to share