Home > Net >  ModuleNotFoundError: No module named 'application' when deploying Flask app on AWS Elastic
ModuleNotFoundError: No module named 'application' when deploying Flask app on AWS Elastic

Time:12-26

I've been struggling with an ostensibly simple error while trying to deploy a Flask app on AWS Elastic Beanstalk for quite some time now. Launching the app gives a 502 Bad Gateway error. The traceback in the logs reads:

Traceback (most recent call last):
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
worker.init_process()
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 92, in init_process
super().init_process()
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/base.py", line 134, in init_process
self.load_wsgi()
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
self.wsgi = self.app.wsgi()
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
return self.load_wsgiapp()
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
return util.import_app(self.app_uri)
File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/gunicorn/util.py", line 359, in import_app
mod = importlib.import_module(module)
File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'application'

My flask app, in application.py, is as simple as it gets:

from flask import Flask
from flask import render_template

application = app = Flask(__name__)

if __name__ == "__main__":
    application.run()

@application.route("/")
def index():
    return render_template('index.html', name=None)

As is my directory structure. I upload ball.zip which contains:

ball/
    application.py
    requirements.txt
    static/
    templates/

The application is using Python 3.7 run on 64bit Amazon Linux 2/3.3.9. I've also checked that the configuration variable WSGIPath is set to application. Does anyone have any pointers on fixing this? Thanks!

CodePudding user response:

You should not have folder "ball" in your zip. Every file should be in the root of the zip, not in the folder "ball".

  • Related