简体   繁体   English

uwsgi找不到Flask应用程序:(未找到可调用的对象或导入错误)

[英]uwsgi cannot find Flask application: (callable not found or import error)

I am roughly following this deployment guide for Flask. 我大致遵循此Flask 部署指南 When I launch my app through uwsgi, I receive the error: 当我通过uwsgi启动应用程序时,收到错误消息:

*** Operational MODE: preforking *** ***操作模式:预分叉***

unable to load app 0 (mountpoint='') (callable not found or import error) 无法加载应用0(mountpoint ='')(找不到可调用或导入错误)

*** 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. 这是与另一个SO问题相同的问题,因此这是python路径问题,但我仍然无法运行我的应用程序。 Here is my setup: 这是我的设置:

/home/btw/prod/
.... app.py
.... inits.py
.... templates/
.... wsgi.py
.... prod.ini
.... env/       <--- virtualenv dir

inits.py 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 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 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): prod.conf(用于启动flask应用程序):

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 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 . 但这抱怨ImportError: No module named prod

Can someone help me out with why uwsgi can't find my application? 有人可以帮我解决uwsgi为什么找不到我的应用程序的问题吗?

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. 调用manager.run()导致找不到该应用程序,但是如果我改用app.run()来绕过Flask的管理器,则uwsgi将成功找到该应用程序。

Why is that? 这是为什么?

Okay, so after a few hours of exploring this mess, I figured it out! 好的,经过几个小时的探索,我弄清楚了!

When running uwsgi, app must be conflicting with some other internal module. 运行uwsgi时, app必须与其他一些内部模块发生冲突。 I've changed my initialization to be application = Flask(__name__) and did from app import application . 我已将初始化更改为application = Flask(__name__) ,并from app import application进行了初始化。 Now my application is being loaded correctly. 现在,我的应用程序已正确加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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