Question

I locally developed an awesome Flask app..now cannot seem to deploy for the life of me.

I am receiving a Internal Server Error with the following error logs:

[Sat May 03 22:24:11.355281 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] mod_wsgi (pid=17560): Target WSGI script '/var/www/dhh/dhh.wsgi' cannot be loaded as Python module.
[Sat May 03 22:24:11.355380 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] mod_wsgi (pid=17560): Exception occurred processing WSGI script '/var/www/dhh/dhh.wsgi'.
[Sat May 03 22:24:11.355467 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] Traceback (most recent call last):
[Sat May 03 22:24:11.355541 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221]   File "/var/www/dhh/dhh.wsgi", line 7, in 
[Sat May 03 22:24:11.355754 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221]     from dhh.app import app as application
[Sat May 03 22:24:11.355815 2014] [:error] [pid 17560:tid 139814473037568] [client 68.40.196.121:52221] ImportError: No module named dhh.app

Current File Structure Tree:

/dhh
|--/app
|------/static
|------/templates
|------__init__.py
|------views.py
|--/flask
|------/bin
|------/include
|------/lib
|------/local
|--/tmp

Relevant Files

  1. __init__.py
from flask import Flask

app = Flask(__name__)
from app import views

if __name__ == "__main__":
    app.run()
  1. views.py
from app import app

@app.route('/')
@app.route('/index')
def index():
    return "Hello, World! This better get working soon."
  1. /etc/apache2/sites-available/dhh.conf

ServerName davidhagan.me ServerAdmin david@davidhhagan.com WSGIScriptAlias / /var/www/dhh/dhh.wsgi Order allow,deny Allow from all Alias /static /var/www/dhh/dhh/app/static Order allow,deny Allow from all ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined

  1. dhh.wsgi
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/dhh/")

from dhh.app import app as application
application.secret_key = 'super secret key'

Although this is a very empty version of the app, it seems to be causing the errrors. I'm sure it is a simple mistake with how the apache server is setup, but cannot figure it out with other SO Q/A's. I would love to know not just how to fix this, but why it is happening!

Update/Solution

I ended up needing to change the path as well as how I was calling the module.

sys.path.insert(0, "/var/www/dhh/")

becomes

sys.path.insert(0, "/var/www/dhh/dhh/")

and

from dhh.app import app as application

becomes

from app import app as application
Was it helpful?

Solution

Instead of:

from dhh.app import app as application

use:

from app import app as application
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top