My WSGI application cannot be loaded as Python module. What am I doing wrong
Question: I have been trying to get a WebAPI to run on the server. However I keep
getting this error everytime I log into the site via the web browser

> Internal Server Error
>
> The server encountered an internal error or misconfiguration and was unable
> to complete your request.
>
> Please contact the server administrator, jordi.duch@gmail.com and inform
> them of the time the error occurred, and anything you might have done that
> may have caused the error.
>
> More information about this error may be available in the server error log.
> Apache/2.2.22 (Ubuntu) Server at complex.ffn.ub.es Port 80

I check the error log file and I have the following.

> [Thu Jul 14 17:16:08 2016] [error] [client 161.116.80.82] mod_wsgi
> (pid=21450): Target WSGI script '/home/xarxes_ub/python_code/configure.wsgi'
> cannot be loaded as Python module.
>
> [Thu Jul 14 17:16:08 2016] [error] [client 161.116.80.82] mod_wsgi
> (pid=21450): Exception occurred processing WSGI script
> '/home/xarxes_ub/python_code/configure.wsgi'.
>
> [Thu Jul 14 17:16:08 2016] [error] [client 161.116.80.82] Traceback (most
> recent call last):
>
> [Thu Jul 14 17:16:08 2016] [error] [client 161.116.80.82] File
> "/home/xarxes_ub/python_code/configure.wsgi", line 10, in
>
> [Thu Jul 14 17:16:08 2016] [error] [client 161.116.80.82] from MenuUB2
> import app as application
>
> [Thu Jul 14 17:16:08 2016] [error] [client 161.116.80.82] ImportError: No
> module named MenuUB2

I configured my .wsgi file based on the directions given on this site
<http://flask.pocoo.org/docs/0.11/deploying/mod_wsgi/>

It mentions specifically "Keep in mind that you will have to actually install
your application into the virtualenv as well. Alternatively there is the
option to just patch the path in the .wsgi file before the import: ` import
sys sys.path.insert(0, '/path/to/the/application')`" Which is what I did

Here is the configure.wsgi file

    
    
    import sys
    sys.path.insert(0, '/home/xarxes_ub/python_code/MenuUB2.py')
    
    from MenuUB2 import app as application
    

In addition here is my apache configuration file that I edited. I highlighted
the lines I added with ###.

    
    
    <VirtualHost *:80>
    
    DocumentRoot /var/www/web_del_grup/
    
    ################Added lines###############
        WSGIScriptAlias /submitFrame /home/xarxes_ub/python_code/configure.wsgi
    WSGIDaemonProcess MenuUB2 user=www-data group=www-data threads=5  
    ################Added lines###############  
    
    #####################Added Directory####################
    <Directory /home/xarxes_ub/python_code>
            WSGIScriptReloading On
        WSGIProcessGroup MenuUB2
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
     </Directory>
    #####################Added Directory####################
    
    ErrorLog /var/log/apache2/error.log
    
    # Options -Indexes +FollowSymLinks MultiViews
    # RewriteEngine on
    # RewriteCond %{HTTP_REFERER} !^$
    # RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?complex.ffn.ub.edu [NC]
    # RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?complex.ffn.ub.es [NC]
    # RewriteRule ^/xarxesub/(.json)$ - [F,NC,L]
    
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
    
        CustomLog /var/log/apache2/access.log combined
    

Please tell me what needs to be done. If I can get this to work I'd be so
relieved. Also note that I tried changing the "configure.wsgi" file to return
a static and it works Example is here

    
    
    def application(environ, start_response):
        status = '200 OK'
        output = 'Hello World!'
    
        response_headers = [('Content-type', 'text/plain'),
                            ('Content-Length', str(len(output)))]
    
       start_response(status, response_headers)
    
        return [output] 
    


Answer: Alright turns out I had a mistake in my configure.wsgi file

I should name the folder that has the application and not the absolute path to
the application so `/home/xarxes_ub/python_code` not
`/home/xarxes_ub/python_code/MenuUB2.py`

Here is the edited configure.wsgi file

    
    
    import sys
    sys.path.insert(0, '/home/xarxes_ub/python_code')
    
    from MenuUB2 import app as application
    

