将简单的Web应用程序部署到Elastic Beanstalk时没有名为“应用程序"的模块错误 [英] No module named 'application' Error while deploying simple web app to Elastic Beanstalk

查看:53
本文介绍了将简单的Web应用程序部署到Elastic Beanstalk时没有名为“应用程序"的模块错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用本教程和它们具有的相同"application.py"文件将Web应用程序部署到Elastic beantalk中:

I am deploying a web app to elastic beanstalk using this tutorial and the same 'application.py' file they have: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html#python-flask-setup-venv

去该站点时出现502错误,并且环境上的健康状况下降/严重.当我检查日志时,我看到了(我认为是问题的根源):

I get a 502 error when going to the site, and degraded/severe health on the environment. When I check the logs, I see this (which I assume is the root of the problem):

Jun 19 22:05:18 ip-172-31-15-237 web: File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module
Jun 19 22:05:18 ip-172-31-15-237 web: return _bootstrap._gcd_import(name[level:], package, level)
Jun 19 22:05:18 ip-172-31-15-237 web: File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
Jun 19 22:05:18 ip-172-31-15-237 web: File "<frozen importlib._bootstrap>", line 983, in _find_and_load
Jun 19 22:05:18 ip-172-31-15-237 web: File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Jun 19 22:05:18 ip-172-31-15-237 web: ModuleNotFoundError: No module named 'application'

这是我的application.py文件:

Here is my application.py file:


from flask import Flask

# print a nice greeting.
def say_hello(username = "World"):
    return '<p>Hello %s!</p>\n' % username

# some bits of text for the page.
header_text = '''
    <html>\n<head> <title>EB Flask Test</title> </head>\n<body>'''
instructions = '''
    <p><em>Hint</em>: This is a RESTful web service! Append a username
    to the URL (for example: <code>/Thelonious</code>) to say hello to
    someone specific.</p>\n'''
home_link = '<p><a href="/">Back</a></p>\n'
footer_text = '</body>\n</html>'

# EB looks for an 'application' callable by default.
application = Flask(__name__)

# add a rule for the index page.
application.add_url_rule('/', 'index', (lambda: header_text +
    say_hello() + instructions + footer_text))

# add a rule when the page is accessed with a name appended to the site
# URL.
application.add_url_rule('/<username>', 'hello', (lambda username:
    header_text + say_hello(username) + home_link + footer_text))

# run the app.
if __name__ == "__main__":
    # Setting debug to True enables debug output. This line should be
    # removed before deploying a production app.
    #application.debug = True
    application.run()

这是我的requirements.txt文件:

And here is my requirements.txt file:

click==7.1.2
Flask==1.1.2
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
numpy==1.16.3
pandas==0.24.2
python-dateutil==2.8.1
pytz==2020.1
six==1.15.0
Werkzeug==1.0.1

我上传到Elastic beantalk的压缩文件夹仅包含这两个文件.我也确实有一个虚拟环境,但是该教程说您不需要它,所以我摆脱了它.

The zipped folder that I upload to elastic beanstalk consists of just these two files. I did have a virtual environment in there too, but the tutorial says you don't need it so I got rid of it.

我也正在运行Python 3.7.1,所以我有pip3.而且我应该注意,仅当我运行python代码时,Web应用程序才能正常工作.

Also I am running Python 3.7.1 so I have pip3. And I should note that the web app works when I just run the python code.

推荐答案

一个可能的原因是使用 Amazon Linux 2 环境而不是 Amazon Linux 1 .

A possible reason is the use of Amazon Linux 2 environment, instead of Amazon Linux 1.

Python环境及其Linux发行版的列表为

The list of python environments and their linux distributions is here.

通过您提供的链接:

在本教程中,我们使用Python 3.6 和相应的Elastic Beanstalk平台版本.

In this tutorial we use Python 3.6 and the corresponding Elastic Beanstalk platform version.

在使用 Amazon Linux 2 环境的Python 3.7时, Amazon Linux 1 环境中支持Python 3.6.

The Python 3.6 is supported in Amazon Linux 1 environment, while you are using Python 3.7 which is for Amazon Linux 2 environment.

AL1和AL2之间有很多区别,这使它们不兼容.

There are many differences between AL1 and AL2, which make them incompatible.

这篇关于将简单的Web应用程序部署到Elastic Beanstalk时没有名为“应用程序"的模块错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆