简体   繁体   中英

Heroku deployment of Flask app - ModuleNotFoundError: No module named 'app'

I am trying to deploy a Flask app to Heroku, however I keep encountering errors:"ModuleNotFoundError: No module named 'app' when I try to open the site on Heroku.

Procfile:

web: gunicorn run:app

run.py

from app import app
# from dir called app, import the object called app
if __name__ == '__main__':
    app.run(debug=True)

Heroku logs:

2020-08-06T18:27:42.941260+00:00 app[web.1]: File "/app/run.py", line 1, in <module>
    2020-08-06T18:27:42.941260+00:00 app[web.1]: from app import app
    2020-08-06T18:27:42.941266+00:00 app[web.1]: ModuleNotFoundError: No module named 'app'
    2020-08-06T18:27:42.941444+00:00 app[web.1]: [2020-08-06 18:27:42 +0000] [11] [INFO] Worker exiting (pid: 11)
    2020-08-06T18:27:43.049679+00:00 app[web.1]: [2020-08-06 18:27:43 +0000] [4] [INFO] Shutting down: Master
    2020-08-06T18:27:43.049793+00:00 app[web.1]: [2020-08-06 18:27:43 +0000] [4] [INFO] Reason: Worker failed to boot.
    2020-08-06T18:27:43.120147+00:00 heroku[web.1]: Process exited with status 3

Project tree structure:

app.\
    │   config.py
    │   forms.py
    │   migration.py
    │   models.py
    │   Procfile
    │   requirements.txt
    │   routes.py
    │   run.py
    │   site.db
    │   __init__.py
    │
    ├───main
    ├───migrations
    ├───posts
    ├───static
    ├───templates
    ├───users

everything looks fine, can you just change from app import app and define app in same file instead of importing, maybe it starts working, as i see no point of failure here, you can look for article below

https://stackabuse.com/deploying-a-flask-application-to-heroku/

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