将 Flask 应用程序导入 Elastic Beanstalk 错误:无法打开文件“mod_wsgi”:[Errno 2] 没有这样的文件或目录
Posted
技术标签:
【中文标题】将 Flask 应用程序导入 Elastic Beanstalk 错误:无法打开文件“mod_wsgi”:[Errno 2] 没有这样的文件或目录【英文标题】:Importing Flask application to Elastic Beanstalk error: can't open file 'mod_wsgi': [Errno 2] No such file or directory 【发布时间】:2018-02-16 23:18:23 【问题描述】:我正在尝试将我的 Flask 应用程序放在 Elastic Beanstalk(Amazon Web Services,EC2)上,但在上传文件后我收到 500 错误。关于可能是什么问题的任何想法?错误日志:
/opt/python/run/venv/bin/python3: can't open file 'mod_wsgi': [Errno 2] No such file or directory
[Fri Sep 08 03:23:05.754341 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] mod_wsgi (pid=13619): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
[Fri Sep 08 03:23:05.754577 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] mod_wsgi (pid=13619): SystemExit exception raised by WSGI script '/opt/python/current/app/application.py' ignored.
[Fri Sep 08 03:23:05.754729 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] Traceback (most recent call last):
[Fri Sep 08 03:23:05.754992 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] File "/opt/python/current/app/application.py", line 11, in <module>
[Fri Sep 08 03:23:05.755007 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] application.run(debug=True)
[Fri Sep 08 03:23:05.755116 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] File "/opt/python/run/venv/lib/python3.4/site-packages/flask/app.py", line 772, in run
[Fri Sep 08 03:23:05.755131 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] run_simple(host, port, self, **options)
[Fri Sep 08 03:23:05.755242 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] File "/opt/python/run/venv/lib/python3.4/site-packages/werkzeug/serving.py", line 737, in run_simple
[Fri Sep 08 03:23:05.755257 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] reloader_type)
[Fri Sep 08 03:23:05.755344 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] File "/opt/python/run/venv/lib/python3.4/site-packages/werkzeug/_reloader.py", line 265, in run_with_reloader
[Fri Sep 08 03:23:05.755358 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] sys.exit(reloader.restart_with_reloader())
[Fri Sep 08 03:23:05.755429 2017] [:error] [pid 13619] [remote 128.12.244.5:31824] SystemExit: 2
我的文件结构如下: file hierarchy
我的 WSGI 路径是 config
【问题讨论】:
【参考方案1】:原来我需要将application.run()
包装在if __name__ == '__main__':
块中。这样可以确保默认情况下不加载本地 WSGI 服务器。
来源:http://flask.pocoo.org/docs/0.11/deploying/mod_wsgi/
【讨论】:
以上是关于将 Flask 应用程序导入 Elastic Beanstalk 错误:无法打开文件“mod_wsgi”:[Errno 2] 没有这样的文件或目录的主要内容,如果未能解决你的问题,请参考以下文章
使用 Elastic Beanstalk 部署 Flask 应用程序时遇到问题
如何使用应用程序工厂将 Flask 应用程序部署到 AWS Elastic beanstalk
使用 pandas 将 Flask 应用程序部署到 Elastic Beanstalk
如何将 Visual Studio Flask 应用程序部署到 Elastic Beanstalk