Target WSGI script cannot be loaded as Python module + no module named Django
<p><em>I know that the question has already been asked here. I've read tons of answers, but nothing helped.</em></p>

<p>I'm using virtualenv (/root/eb-virt); my Django project is called mediar. All public files are stored in /var/www/html/xxx.com/public_html/</p>

<p>From error log:</p>

<pre><code>[Sun Oct 16 18:40:11.737747 2016] [:error] [pid 27659] [client 128.75.240.205:60486] mod_wsgi (pid=27659): Target WSGI script '/var/www/html/xxx.com/django.wsgi' cannot be loaded as Python module.
[Sun Oct 16 18:40:11.737808 2016] [:error] [pid 27659] [client 128.75.240.205:60486] mod_wsgi (pid=27659): Exception occurred processing WSGI script '/var/www/html/xxx.com/django.wsgi'.
[Sun Oct 16 18:40:11.745983 2016] [:error] [pid 27659] [client 128.75.240.205:60486] Traceback (most recent call last):
[Sun Oct 16 18:40:11.746153 2016] [:error] [pid 27659] [client 128.75.240.205:60486]   File "/var/www/html/xxx.com/django.wsgi", line 9, in &lt;module&gt;
[Sun Oct 16 18:40:11.746165 2016] [:error] [pid 27659] [client 128.75.240.205:60486]     import django.core.handlers.wsgi
[Sun Oct 16 18:40:11.746191 2016] [:error] [pid 27659] [client 128.75.240.205:60486] ImportError: No module named 'django'
</code></pre>

<p>My apache2.conf:</p>

<pre><code>Mutex file:${APACHE_LOCK_DIR} default

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive Off

MaxKeepAliveRequests 100

KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

&lt;Directory /&gt;
    Options FollowSymLinks
    AllowOverride None
    Require all denied
&lt;/Directory&gt;

&lt;Directory /usr/share&gt;
    AllowOverride None
    Require all granted
&lt;/Directory&gt;

&lt;Directory /var/www/&gt;
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
&lt;/Directory&gt;

#&lt;Directory /srv/&gt;
#   Options Indexes FollowSymLinks
#   AllowOverride None
#   Require all granted
#&lt;/Directory&gt;

AccessFileName .htaccess

&lt;FilesMatch "^\.ht"&gt;
    Require all denied
&lt;/FilesMatch&gt;

LogFormat "%v:%p %h %l %u %t \"%r\" %&gt;s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %&gt;s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %&gt;s %O" common
LogFormat "%{Referer}i -&gt; %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

&lt;IfModule mpm_prefork_module&gt;
    StartServers 4
    MinSpareServers 20
    MaxSpareServers 40
    MaxClients 200
    MaxRequestsPerChild 4500
&lt;/IfModule&gt;


LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so

WSGIScriptAlias / /var/www/html/xxx.com/public_html/mediar/mediar/wsgi.py
WSGIPythonPath /var/www/html/xxx.com/public_html:/root/eb-virt/lib/python3.4/site-packages/

&lt;Directory /var/www/html/xxx.com/public_html/mediar/mediar/&gt;
&lt;Files wsgi.py&gt;
Require all granted
&lt;/Files&gt;
&lt;/Directory&gt;
</code></pre>

<p>My xxx.com.conf:</p>

<pre><code>&lt;VirtualHost *:80&gt;
  ServerAdmin xxx@xxx.com
  ServerName  xxx.com
  ServerAlias www.xxx.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /var/www/html/xxx.com/public_html
  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/xxx.com/log/error.log
  CustomLog /var/www/html/xxx.com/log/access.log combined
WSGIScriptAlias / /var/www/html/xxx.com/django.wsgi
&lt;/VirtualHost&gt;
</code></pre>

<p>And, finally, my django.wsgi:</p>

<pre><code>#!/usr/bin/python 
import os, sys 

PROJECT_ROOT = '/var/www/html/xxx.com/' 
sys.path.append(PROJECT_ROOT) 

os.environ['DJANGO_SETTINGS_MODULE'] = 'mediar.settings' 

import django.core.handlers.wsgi 
application = django.core.handlers.wsgi.WSGIHandler()
</code></pre>

<p>I've tried </p>

<pre><code>$ sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py3
</code></pre>

<p>, it didn't help. </p>

<p>What should I do?</p>

<p>I would first try using the right python shebang in your wsgi file.  Shouldnât it be something like the following?</p>

<pre><code>#!/root/eb-virt/bin/python
</code></pre>

<p>And then the second thing would be to explicitly add the virtualenv to the <code>sys.path</code> append in the wsgi file</p>

<pre><code>sys.path.append('/root/eb-virt/lib/python3.4/site-packages')
</code></pre>

python django apache mod-wsgi