mod_wsgi: Target WSGI script cannot be loaded as a python module and ImportError: No module named 'django'

I’m try to deploy virtual host my django project into apache2 via mod_wsgi WSGIDaemon method, i’m using ubuntu 16.04 and i’m getting following error.

From apache2 error log:

[Tue Dec 11 11:55:31.748517 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] mod_wsgi (pid=14231): Target WSGI script '/var/www/html/rasa_django/rasa_django/wsgi.py' cannot be loaded as Python module. [Tue Dec 11 11:55:31.748570 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] mod_wsgi (pid=14231): Exception occurred processing WSGI script '/var/www/html/rasa_django/rasa_django/wsgi.py'. [Tue Dec 11 11:55:31.748639 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] Traceback (most recent call last): [Tue Dec 11 11:55:31.748657 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] File "/var/www/html/rasa_django/rasa_django/wsgi.py", line 12, in [Tue Dec 11 11:55:31.748662 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] from django.core.wsgi import get_wsgi_application [Tue Dec 11 11:55:31.748677 2018] [wsgi:error] [pid 14231:tid 139821891782400] [remote ::1:44748] ImportError: No module named 'django' [Tue Dec 11 11:55:31.787336 2018] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] mod_wsgi (pid=14231): Target WSGI script '/var/www/html/rasa_django/rasa_django/wsgi.py' cannot be loaded as Python module. [Tue Dec 11 11:55:31.787379 2018] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] mod_wsgi (pid=14231): Exception occurred processing WSGI script '/var/www/html/rasa_django/rasa_django/wsgi.py'. [Tue Dec 11 11:55:31.787447 2018] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] Traceback (most recent call last): [Tue Dec 11 11:55:31.787465 2018] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] File "/var/www/html/rasa_django/rasa_django/wsgi.py", line 12, in [Tue Dec 11 11:55:31.787470 2018] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] from django.core.wsgi import get_wsgi_application [Tue Dec 11 11:55:31.787484 2018] [wsgi:error] [pid 14231:tid 139821849777920] [remote ::1:38604] ImportError: No module named 'django'

In my host file 000-default.conf:

ServerName www.rasa_django.com 
DocumentRoot /var/www/html/rasa_django 
ErrorLog /var/www/logs/error.log 
CustomLog /var/www/logs/custom.log combined

Alias /static /var/www/html/rasa_django/static

<Directory /var/www/html/rasa_django/static>
    Require all granted
</Directory>

<Directory /var/www/html/rasa_django/rasa_django>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>


WSGIDaemonProcess rasa_django.com python-path=/var/www/html/rasa_django python-home=/home/aarbor_01/env_site1
WSGIProcessGroup rasa_django.com
WSGIScriptAlias / /var/www/html/rasa_django/rasa_django/wsgi.py

Here my wsgi.py file:

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rasa_django.settings')

application = get_wsgi_application()

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 29 (13 by maintainers)

Most upvoted comments

If you want to use Anaconda Python, you want to do:

sudo a2dismod wsgi
sudo apt-get uninstall libapache2-mod-wsgi-py3

and use pip install method to install mod_wsgi in the Python virtual environment.

Then create a wsgi.load file in the mods-available directory of Apache which contains the output from running:

mod_wsgi-express module-config

Then run:

sudo a2enmod wsgi

How did you install mod_wsgi?

It must be compiled for the specific Python installation/version you are using. You cannot use system package for mod_wsgi (which is compiled for system package for Python), with a virtual environment created using Anaconda Python.

For a start, python-home is not meant to refer to site-packages. It is meant to refer to the root of the Python virtual environment. See: