I am roughly following this deployment guide for Flask. When I launch my app through uwsgi, I receive the error:
*** Operational MODE: preforking ***
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
It is the same issue as this other SO question, so it is a python path problem, but I still can't get my app to run. Here is my setup:
/home/btw/prod/
.... app.py
.... inits.py
.... templates/
.... wsgi.py
.... prod.ini
.... env/ <--- virtualenv dir
inits.py
# This initializes everything
from flask import Flask
#... other imports
app = Flask(__name__)
app.debug = False
# Flask-Migrate
migrate = Migrate(app,db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
app.py
# This holds the main application code and routes
from inits import *
@app.route('/doit')
def doit():
return render_template('doit.html')
if __name__ == '__main__':
manager.run()
prod.ini
[uwsgi]
module = wsgi
master = true
processes = 5
socket = prod.sock
chmod-socket = 660
vacuum = true
die-on-term = true
prod.conf (used to start the flask app):
description "uWSGI server instance configured to serve prod"
start on runlevel [2345]
stop on runlevel [!2345]
setuid btw
setgid www-data
env PATH=/home/btw/prod/env/bin
chdir /home/btw/prod
exec uwsgi --ini prod.ini
wsgi.py
from app import manager
if __name__ == '__main__':
manager.run()
I also tried doing:
from prod import app
if __name__ == '__main__':
manager.run()
But this complains about ImportError: No module named prod
.
Can someone help me out with why uwsgi can't find my application?
EDIT:
I think I found the problem, but I dont know what the solution is. Calling manager.run()
causes the application to not be found, but if I just use app.run()
instead, bypassing Flask's manager, uwsgi successfully locates the application.
Why is that?