[英]ModuleNotFoundError: No module named 'application' when deploying Flask app on AWS Elastic Beanstalk
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.在尝试在 AWS Elastic Beanstalk 上部署 Flask 应用程序时,我一直在努力解决一个表面上简单的错误。 Launching the app gives a
502 Bad Gateway
error.启动应用程序会出现
502 Bad Gateway
错误。 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:我在
application.py
中的 flask 应用程序非常简单:
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.zip
,其中包含:
ball/
application.py
requirements.txt
static/
templates/
The application is using Python 3.7 run on 64bit Amazon Linux 2/3.3.9.该应用程序使用 Python 3.7 在 64 位 Amazon Linux 2/3.3.9 上运行。 I've also checked that the configuration variable
WSGIPath
is set to application
.我还检查了配置变量
WSGIPath
是否设置为application
。 Does anyone have any pointers on fixing this?有人对解决此问题有任何指示吗? Thanks!
谢谢!
You should not have folder "ball" in your zip. zip 中不应有文件夹“ball”。 Every file should be in the root of the zip, not in the folder "ball".
每个文件都应该在 zip 的根目录中,而不是在文件夹“ball”中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.