我正在尝试将我的 Flask 应用程序部署到 Heroku,但出现此错误 No module named 'app' on running the command
。
heroku logs --tail
我的 Flask 应用程序具有以下文件夹结构
我收到以下错误。
2020-12-27T14:26:26.956274+00:00 app[web.1]: Traceback (most recent call last):
2020-12-27T14:26:26.956285+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2020-12-27T14:26:26.956289+00:00 app[web.1]: worker.init_process()
2020-12-27T14:26:26.956289+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 119, in init_process
2020-12-27T14:26:26.956290+00:00 app[web.1]: self.load_wsgi()
2020-12-27T14:26:26.956290+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
2020-12-27T14:26:26.956291+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2020-12-27T14:26:26.956298+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2020-12-27T14:26:26.956299+00:00 app[web.1]: self.callable = self.load()
2020-12-27T14:26:26.956299+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
2020-12-27T14:26:26.956300+00:00 app[web.1]: return self.load_wsgiapp()
2020-12-27T14:26:26.956300+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
2020-12-27T14:26:26.956300+00:00 app[web.1]: return util.import_app(self.app_uri)
2020-12-27T14:26:26.956301+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 358, in import_app
2020-12-27T14:26:26.956301+00:00 app[web.1]: mod = importlib.import_module(module)
2020-12-27T14:26:26.956301+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
2020-12-27T14:26:26.956302+00:00 app[web.1]: return _bootstrap._gcd_import(name[level:], package, level)
2020-12-27T14:26:26.956302+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 994, in _gcd_import
2020-12-27T14:26:26.956303+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 971, in _find_and_load
2020-12-27T14:26:26.956303+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
2020-12-27T14:26:26.956309+00:00 app[web.1]: ModuleNotFoundError: No module named 'app'
这是我的 app.py 文件
from flask import Flask, abort, jsonify, request, render_template
import joblib
from feature import *
import json
pipeline = joblib.load('./pipeline.sav')
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
if __name__ == '__main__':
app.run(host='0.0.0.0')
这是我的Procfile:
web: gunicorn app:app
我在这里遇到了很多类似的问题,但没有一个能帮我解决。这个错误是指 app.py 文件吗?我该如何解决?