webapp2 mod_wsgi apache centos 500 internal server error; The wsgi script cannot be loaded as Python module
<p>I'm using <code>webapp2</code> to develop my app and I want to deploy it on apache using <code>mod_wsgi</code> but I'm getting 500 Internal server Error along with import webapp2 no module found error in error_log.</p>

<p>I installed <code>WebOb</code>, <code>Paste</code>, <code>webapp2</code> on to the system as well as in <code>virtualenv</code> and tested on python environment </p>

<pre><code>&gt;&gt; import webapp2 
</code></pre>

<p>and it's working fine.</p>

<p>Error is:</p>

<pre><code>&gt; mod_wsgi (pid=15727): Target WSGI script '/var/www/html/app/main.py'
&gt; cannot be loaded as Python module.
&gt;     mod_wsgi (pid=15727): Exception occurred processing WSGI script '/var/www/html/app/main.py'.Traceback (most recent call last):File
&gt; "/var/www/html/app/main.py", line 20, in &lt;module&gt;
&gt;     import webapp2
</code></pre>

<p>My <code>httpd.conf</code> file configuration is below</p>

<pre><code>WSGISocketPrefix /var/run/wsgi
WSGIPythonPath /var/www/html/app/env/lib/python2.7/site-packages

&lt;VirtualHost 10.10.10.9&gt;
    ServerName prep2016.msitprogram.net
    ServerAlias prep2016.msitprogram.net
    ServerAdmin sirimala.sreenath@gmail.com
#    DocumentRoot /var/www/html/app

    #WSGIDaemonProcess app python-path=/var/www/html/app:/var/www/html/app/env/lib/python2.7/site-packages
    WSGIDaemonProcess prep2016.msitprogram.net processes=2 threads=15
    WSGIScriptAlias / /var/www/html/app/main.py
    &lt;Directory /var/www/html/app/&gt;
#       options +ExecCGI
#       DirectoryIndex main.py
#       Order allow,deny
#       Allow from all  
#    &lt;/Directory&gt;
#    DocumentRoot /var/www/html/app
#    WSGIDaemonProcess prep2016.msitprogram.net processes=2 threads=15 
    #WSGIDaemonProcess prep2016.msitprogram.net user=apache group=apache processes=2 threads=15 
    WSGIProcessGroup prep2016.msitprogram.net
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptReloading On
#    WSGIScriptAlias / /var/www/html/app/main.py
#    WSGIPythonPath /var/www/html/app

#    &lt;Directory /var/www/html/app&gt;
#       &lt;Files main.py&gt;
        Order allow,deny
        Allow from all
#       Require all granted
#       &lt;/Files&gt;    
&lt;/Directory&gt;
&lt;/VirtualHost&gt;
</code></pre>

<p>This is my <code>main.py</code> file content</p>

<pre><code>#!/usr/bin/env python

import os
import webapp2
import jinja2
import logging
import json
import datetime
import jwt.api_jwt
import os, sys
ABSPATH = os.path.dirname (__ file__)
sys.path.append (ABSPATH)
os.chdir (ABSPATH)
sys.path.append('/var/www/html/app/env/lib/python2.7/site-packages')
#site.addsitedir('/var/www/html/app/env/lib/python2.7/site-packages')

class MainPage(Webapp2.RequestHandler):
        def get(self):
                self.response.out.write("hello world")

app = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)

def main():
    from paste import httpserver
    httpserver.serve(app, host='prep2016.msitprogram.net', port='8080')

if __name__ == '__main__':
    main()
</code></pre>