0

I am trying to run my Flask app under uWSGI and am getting:

unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***

The layout is:

/opt/myapp
/opt/myapp/wsgi.py
/opt/myapp/run.py
/opt/myapp/lib
/opt/myapp/app
/opt/myapp/app/blueprints.py
/opt/myapp/app/filters
/opt/myapp/app/filters/__init__.py
/opt/myapp/app/__init__.py
/opt/myapp/app/main.py

app/__init__.py contains the usual:

from flask import Flask
app = Flask(__name__)

app/main.py looks like:

import blueprints
import filters

from app import app

def run(debug, host='0.0.0.0'):
    app.run(debug=debug, host=host)

wsgi.py looks like:

if __name__ == '__main__':
    from app.main import app as application
    application.run(host='0.0.0.0')

If I run python wsgi.py from the CLI, it works fine, the usual :5000 server.

If I run:

uwsgi --socket 0.0.0.0:8080 --protocol=http -w wsgi

I see the error, it cannot load the application.

Wells
  • 10,415
  • 14
  • 55
  • 85

3 Answers3

3

uWSGI imports your wsgi.py. So this code is never executed:

if __name__ == '__main__':
    from app.main import app as application
    application.run(host='0.0.0.0')

You should create the application at module level:

from app.main import app as application

if __name__ == "__main__":
    application.run(...)

You must of course leave the .run() method inside the main block, because you don't want uWSGI to execute that.

Wombatz
  • 4,958
  • 1
  • 26
  • 35
-1

Have you tried something like ...

uwsgi -s 0.0.0.0:8080 --protocol=http --module myapp --callable app

I'm not 100% sure the --module and --callable options are correct, because I don't have your actual code in front of me, might be something like --module myapp.app --callable main or some other variant

From the documentation on using uwsgi together.

http://flask.pocoo.org/docs/0.10/deploying/uwsgi/

Alex
  • 1,993
  • 1
  • 15
  • 25
-1

If it's in virtualenv You have to activate it by adding:

execfile(activate_this, dict(__file__=activate_this))

And I think You should define project directory:

import sys

sys.path.append('/opt/myapp/app')
Filip
  • 128
  • 5