The problem

Apache gives an error 500 (internal server error) when trying to access website running django 1.9 using wsgi based on the tutorial given at Running the server using the developmental server ( runserver) works fine.

Looking in the apache error log reveals:

[stuff] mod_wsgi (pid=20304): Target WSGI script '/django/XY_django/XY/XY/' cannot be loaded as Python module. 
[stuff] mod_wsgi (pid=20304): Exception occurred processing WSGI script '/django/XY_django/XY/XY/'.

[python traceback]

[stuff] ImportError: No module named ‘XY’

[this error is repeated twice]

Various resources mention the same or similar problems:

  3. lots of others

Things I tried

  1. Wrong ownership of django dir and files.
    • Was root, changed to www-data.
    • No change.
  1. Wrong version of wsgi.
    • Ran:
    • sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
      sudo apt-get install libapache2-mod-wsgi-py3
    • No, used the correct version.
  1. Wrong code with the static block in apache config.
    • No, error persists after commenting it out.
  1. WSGIDaemonProcess python-path is wrong.
    • I noticed that the path given in the tutorial has two folders separated by :, not just one:
    • WSGIDaemonProcess django python-path=/home/user/myproject:/home/user/myproject/myprojectenv/lib/python2.7/site-package
      WSGIDaemonProcess django python-path=/django/env/lib/python3.4/site-packages
    • Replaced with:
    • WSGIDaemonProcess django python-path=/django/XY_django/XY:/django/env/lib/python3.4/site-packages
    • Worked!