ModuleNotFoundError: No module named 'application' when deploying Flask app on AWS Elastic Beanstalk
ModuleNotFoundError: No module named 'application' when deploying Flask app on AWS Elastic Beanstalk
在尝试在 AWS Elastic Beanstalk 上部署 Flask 应用程序时,我一直在为一个看似简单的错误而苦苦挣扎很长一段时间。启动应用程序会出现 502 Bad Gateway
错误。日志中的回溯显示为:
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'
我的 Flask 应用程序在 application.py
中非常简单:
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)
我的目录结构也是如此。我上传 ball.zip
其中包含:
ball/
application.py
requirements.txt
static/
templates/
该应用程序在 64 位 Amazon Linux 2/3.3.9 上使用 Python 3.7 运行。我还检查了配置变量 WSGIPath
是否设置为 application
。有没有人对解决这个问题有任何指示?谢谢!
您的 zip 中不应包含文件夹“ball”。每个文件都应该在 zip 的根目录中,而不是在文件夹“ball”中。
在尝试在 AWS Elastic Beanstalk 上部署 Flask 应用程序时,我一直在为一个看似简单的错误而苦苦挣扎很长一段时间。启动应用程序会出现 502 Bad Gateway
错误。日志中的回溯显示为:
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'
我的 Flask 应用程序在 application.py
中非常简单:
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)
我的目录结构也是如此。我上传 ball.zip
其中包含:
ball/
application.py
requirements.txt
static/
templates/
该应用程序在 64 位 Amazon Linux 2/3.3.9 上使用 Python 3.7 运行。我还检查了配置变量 WSGIPath
是否设置为 application
。有没有人对解决这个问题有任何指示?谢谢!
您的 zip 中不应包含文件夹“ball”。每个文件都应该在 zip 的根目录中,而不是在文件夹“ball”中。