简体   繁体   中英

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

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM