【问题标题】:No module named 'flask_cors' when using gunicorn使用 gunicorn 时没有名为“flask_cors”的模块
【发布时间】:2020-02-14 21:39:03
【问题描述】:

我的应用程序在使用 python run.py 运行时运行正常,但在使用 gunicorn gunicorn run:app 运行时,它给出了 'flask_cors' module not found 错误。

我创建了一个基本应用程序以使其更易于理解,我已经调试了很多但没有工作,因为它在 python run.py 上运行良好,所以它应该在使用 gunicorn 时运行,我想我没有实际上了解 gunicorn 是如何实际导入导致此错误的。

工作目录

.
├── flaskblog
│   ├── __init__.py
│   └── routes.py
├── requirements.txt
└── run.py

1 directory, 4 files

__init__.py文件

from flask import Flask
from flask_cors import CORS

app = Flask(__name__)
CORS(app, support_credentials=True)

from flaskblog import routes

routes.py 文件

from flaskblog import app
from flask_cors import cross_origin


@app.route("/")
@cross_origin(supports_credentials=True)
def home():
    return "home"

run.py 文件

from flaskblog import app

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

requirements.txt

Flask
gunicorn
flask-cors

编辑:

我再次运行程序以获取错误跟踪,这一次成功了吗? 它从 '127.0.0.1:8000' 开始,所以我使用了 gunicorn -b 0.0.0.0 run:app

现在怎么样了?

如果您有更好的问题标题,请编辑它,因为现在我的问题是它的奇怪行为。

【问题讨论】:

    标签: python heroku flask gunicorn


    【解决方案1】:

    删除了 pycache 并再次创建了环境,这次它可以正常工作并成功托管在 heroku 上。 在我的 procfile 中

    web: gunicorn gettingstarted.wsgi
    web: gunicorn run:app
    

    【讨论】:

      猜你喜欢
      • 2021-10-19
      • 1970-01-01
      • 2017-01-20
      • 1970-01-01
      • 2015-04-24
      • 2019-11-28
      • 2018-10-23
      • 2019-12-01
      • 2020-05-04
      相关资源
      最近更新 更多