Search code examples
djangomod-wsgiwsgidjango-wsgi

Django Apache wsgi virtualenv import error


I'm trying to deploy Django (located in a virtualenv) on Apache using WSGI deploying. I'm following the default tutorial from https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/

wsgi.py (the default one which Django generated, with the comments dropped):

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

apache2.conf (its the same httpd.conf just in Debian ). Appended this to the end:

WSGIScriptAlias / /home/user/Desktop/expofit/expofit_hg/py/server/server/wsgi.py
WSGIDaemonProcess example.com python-path=/home/user/Desktop/expofit/expofit_hg/py/server:/home/user/Desktop/expofit/expofit_env/lib/python2.7/site-packages
WSGIProcessGroup example.com

<Directory /home/user/Desktop/expofit/expofit_hg/py/server/server>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

Alias /static/ /home/user/Desktop/expofit/expofit_hg/py/server/server/static

<Directory /home/user/Desktop/expofit/expofit_hg/py/server/server/static>
Order deny,allow
Allow from all
</Directory>

However, this ends with an error:

[Thu Dec 06 17:08:40 2012] [error] [client 192.168.56.1] ImportError: No module named django.core.wsgi

It seems that the standard python is accessible, since

import os

yields no errors. So it seems that modules imported from the virtualenv aren't importable. The tutorial said:

A further change required to the above configuration if you use daemon mode is that you can't use WSGIPythonPath; instead you should use the python-path option to WSGIDaemonProcess, for example:

WSGIDaemonProcess example.com python-path=/path/to/mysite.com:/path/to/venv/lib/python2.7/site-packages
WSGIProcessGroup example.com

What am I missing?


Solution

  • The problem was in the permissions. I didn't check who was the user, and what the permissions were at the beginning, however, when I changed the permission 777 to all the directories containing Django code files, it started working.

    I'm aware that a person has to be as careful as possible with permissions, and that giving 777 to everything isn't the best way to do it but should check how to make it work with minimum permission change. It however solves the problem in the question.