Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running uwsgi with virtualenv and flask

When trying to run my flask application I get the error:

uwsgi no module named site

I created a configuration file as such:

[uwsgi]
socket = 127.0.0.1:8000
processes = 4
virtualenv = /var/www/test/venv
chdir = /var/www/test
module = run
callable = manager
logto = var/www/uwsgi.log

The location of my run.py is /var/www/test/run.py with the following code:

from flask.ext.migrate import Migrate, MigrateCommand
from flask.ext.script import Manager
from app import app, db

if __name__ == "__main__":
    migrate = Migrate(app, db)
    manager = Manager(app)
    manager.add_command('db', MigrateCommand)
    manager.run()

Can anyone help me understand where I have gone wrong please? I am running a system wide UWSGI.

EDIT

I installed uwsgi and virtualenv using pip and I have the following versions:

  • uWSGI==2.0.2
  • virtualenv==1.11.4

My system wide python version (and the one inside my venv) is: Python 2.7.3

like image 684
Jimmy Avatar asked Mar 05 '14 11:03

Jimmy


People also ask

Which Python is uWSGI using?

It seems that uWSGI binds the Python 3 runtime during install. Once you've pip installed a version, it uses the cached wheel (hence cached Python version).

Does flask work with nginx?

If you want to run Flask in production, be sure to use a production-ready web server like Nginx, and let your app be handled by a WSGI application server like Gunicorn.


1 Answers

You don't want use app.run() (or manager.run()) and uwsgi at the same time, because:

  • app.run()/manager.run() launch a developpment server (Flask doc, Watch Out, Flask doc app.run())
  • uwsgi is a already a server

So you just need to properly setup uwsgi, something like that should work:

app-name   = test 

pidfile    = /run/uwsgi/%(app-name)/pid
socket     = /run/uwsgi/%(app-name)/socket

logto      = /var/log/uwsgi/%(app-name).log
log-date   = true

processes  = 4
plugins    = http,python

base       = /srv/www/%(app-name)
home       = %(base)/venv # http://uwsgi-docs.readthedocs.org/en/latest/Options.html#home-virtualenv-venv-pyhome
pythonpath = %(base)/venv # http://uwsgi-docs.readthedocs.org/en/latest/Options.html#pythonpath-python-path-pp

module     = app 
callable   = app

chdir      = %(base)
like image 137
Dysosmus Avatar answered Sep 20 '22 03:09

Dysosmus