Flask and Heroku - ModuleNotFoundError: No module named 'app'

后端 未结 3 1429
一整个雨季
一整个雨季 2020-12-31 17:08

I\'m trying to deploy a Flask app to Heroku. After deploying, application crashes and I get an error ModuleNotFoundError: No module named \'app\'.

Project structure

相关标签:
3条回答
  • 2020-12-31 17:37

    web:gunicorn app:app is standard Procfile. It expects that your .py file should be named app.py.

    If you want to change .py name you should change Procfile as well. web:gunicorn my_app_name:app After that you can name your file - my_app_name.py

    0 讨论(0)
  • On your local machine, at the base of your repository, you need to add a Procfile (exactly like this).

    Inside that, paste only one line: web: gunicorn :app

    Example: If you want to trigger init.py, then:

    web: gunicorn init:app
    
    0 讨论(0)
  • 2020-12-31 18:01

    In my case, this was resolved after I made the following changes, of course committing the changes before pushing to heroku:

    1) ran pip freeze > requirements.txt,

    2) moved my app.py to a different directory, and updated Procfile, manage.py -all files importing app.py- and to reflect the new location. I'm not sure if moving the file actually made a difference, it seems unlikely, but regardless, it's worth verifying all files that import app have the correct path

    0 讨论(0)
提交回复
热议问题