用virtualenv和烧瓶运行uwsgi

时间:2014-03-05 11:48:42

标签: python flask debian uwsgi

尝试运行我的烧瓶应用程序时出现错误:

uwsgi no module named site

我创建了一个配置文件:

[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

我的run.py位置是/var/www/test/run.py,代码如下:

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()

任何人都可以帮我理解我出错的地方吗?我正在运行一个系统范围的UWSGI。

编辑

我使用pip安装了uwsgi和virtualenv,我有以下版本:

  • uWSGI == 2.0.2
  • 的virtualenv == 1.11.4

我的系统范围的python版本(以及我的venv中的版本)是:Python 2.7.3

1 个答案:

答案 0 :(得分:3)

您不希望同时使用app.run()(或manager.run())和uwsgi,因为:

所以你只需要正确设置uwsgi,这样的东西应该可以工作:

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)