uWSGI cannot find "application" using Flask and Virtualenv
- by skyler
Using uWSGI to serve a simple wsgi app, (a simple "Hello, World") my configuration works, but when I try to run a Flask app, I get this in uWSGI's error logs:
current working directory: /opt/python-env/coefficient/lib/python2.6/site-packages
writing pidfile to /var/run/uwsgi.pid
detected binary path: /opt/uwsgi/uwsgi
setuid() to 497
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3
Python version: 2.6.6 (r266:84292, Jun 18 2012, 14:18:47) [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)]
Set PythonHome to /opt/python-env/coefficient/
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xbed3b0
your server socket listen backlog is limited to 100 connections
*** Operational MODE: single process ***
added /opt/python-env/coefficient/lib/python2.6/site-packages/ to pythonpath.
unable to find "application" callable in file /var/www/coefficient/flask.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***`
Note in particular this part of the log:
unable to find "application" callable in file /var/www/coefficient/flask.py
unable to load app 0 (mountpoint='') (callable not found or import error)
**no app loaded. going in full dynamic mode**
This is my Flask app:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, World, from Flask!"
Before I added my Virtualenv's pythonpath to my configuration file, I was getting an ImportError for Flask. I solved this though, I believe (I'm not receiving errors about it anymore) and here is my complete configuration file:
uwsgi:
#socket: /tmp/uwsgi.sock
socket: 127.0.0.1:3031
daemonize: /var/log/uwsgi.log
pidfile: /var/run/uwsgi.pid
master: true
vacuum: true
#wsgi-file: /var/www/coefficient/coefficient.py
wsgi-file: /var/www/coefficient/flask.py
processes: 1
virtualenv: /opt/python-env/coefficient/
pythonpath: /opt/python-env/coefficient/lib/python2.6/site-packages
This is how I start uWSGI, from an rc script:
/opt/uwsgi/uwsgi --yaml /etc/uwsgi/conf.yaml --uid uwsgi
And if I try to view the Flask program in a browser, I get this:
**uWSGI Error**
Python application not found
Any help is appreciated.