简体   繁体   中英

No module named "app" error on deploying Flask app to Heroku

I am trying to deploy my flask app to Heroku, but I am getting this error No module named 'app' on running the command .

heroku logs --tail

My flask app has the following folder structure

在此处输入图像描述

I get the following error.

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'

Here is my app.py file

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

Here is my Procfile:

web: gunicorn app:app

I went through a lot of similar questions here, but none of them could help me resolve it. Is this error referring to the app.py file? How can I resolve this?

I know it's an old question but I faced this error recently, and let me add that besides moving the code up one level as suggested, to be in the same directory as the Procfile , the --chdir gunicorn parameter could be used. In this case the Procfile contents could have been

web: gunicorn app:app --chdir App

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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