gpt4 book ai didi

python - gunicorn 导入错误 : No module named flask

转载 作者:行者123 更新时间:2023-12-04 11:41:37 24 4
gpt4 key购买 nike

我有一个 anaconda 虚拟环境,我已经使用 pip 在虚拟环境中安装了 Flask
当我运行我的应用程序时

$ python app.py 

然后它工作正常,但是当我用 gunicorn 运行它时,我没有显示没有模块 flask
应用程序

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
return "Hello World"

if __name__ == '__main__':
app.run(debug=True)

wsgi.py

from app import app
if __name__ == "__main__":
app.run()
 $ gunicorn --bind 0.0.0.0:8000 wsgi
[2019-07-23 12:39:24 +0000] [25612] [INFO] Starting gunicorn 19.9.0
[2019-07-23 12:39:24 +0000] [25612] [INFO] Listening at: http://0.0.0.0:8000 (25612)
[2019-07-23 12:39:24 +0000] [25612] [INFO] Using worker: sync
[2019-07-23 12:39:24 +0000] [25616] [INFO] Booting worker with pid: 25616
[2019-07-23 12:39:24 +0000] [25616] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/rahul/.local/lib/python2.7/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
File "/home/rahul/test_folder/wsgi.py", line 1, in <module>
from app import app
File "/home/rahul/test_folder/app.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask
[2019-07-23 12:39:24 +0000] [25616] [INFO] Worker exiting (pid: 25616)
[2019-07-23 12:39:24 +0000] [25612] [INFO] Shutting down: Master
[2019-07-23 12:39:24 +0000] [25612] [INFO] Reason: Worker failed to boot.

最佳答案

我想你在运行 gunicorn 时忘记添加 app

gunicorn --bind 0.0.0.0:8000 wsgi:app
它会像这样运行
→ gunicorn --bind 0.0.0.0:8000 wsgi:app
[2021-06-06 12:39:44 +0700] [54561] [INFO] Starting gunicorn 20.1.0
[2021-06-06 12:39:44 +0700] [54561] [INFO] Listening at: http://0.0.0.0:8000 (54561)
[2021-06-06 12:39:44 +0700] [54561] [INFO] Using worker: sync
[2021-06-06 12:39:44 +0700] [54563] [INFO] Booting worker with pid: 54563
并像这样测试
→ curl http://localhost:8000
Hello World%

关于python - gunicorn 导入错误 : No module named flask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57158673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com