Flask Beanstalk 部署错误

Posted

技术标签:

【中文标题】Flask Beanstalk 部署错误【英文标题】:Flask Beanstalk deployment errors 【发布时间】:2017-11-09 08:16:29 【问题描述】:

我对 Python 比较陌生,我正在尝试将 Flask 应用程序部署到 AWS Beanstalk。我遵循了官方教程,并浏览了很多关于 Flask / Django on Beanstalk 的部署问题的在线资源(这里或其他地方)。没有成功,我不断收到无法修复的错误。 在我的应用程序结构下方:

|-application.py
|-config.py
|-const.py
|-requirements.txt
|-app/
|--__init.py__
|--views.py
|--models.py
|--static/
|--templates/

我的应用程序.py

from app.views import application

application.run(debug=False)

views.py 文件的前几行包含 Flask 应用程序的声明:

from flask import Flask, render_template, redirect, url_for, session, request, abort
from flask_bootstrap import Bootstrap
from . models import Datalayer, Config, Signin
from . util import check_user
from flask_basicauth import BasicAuth
from flask_bcrypt import Bcrypt
from faker import Faker
from htmlmin.minify import html_minify
fake = Faker()


application = app = Flask(__name__)
app.config.from_object('config')

bootstrap = Bootstrap(app)
basic_auth = BasicAuth(app)
bcrypt = Bcrypt(app)

最后是/var/log/eb-activity.log的内容

 SyntaxError: invalid syntax
      2017-06-07 19:08:18,171 ERROR    Error installing dependencies: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status 1
      Traceback (most recent call last):
        File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 22, in main
          install_dependencies()
        File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 18, in install_dependencies
          check_call('%s install -r %s' % (os.path.join(APP_VIRTUAL_ENV, 'bin', 'pip'), requirements_file), shell=True)
        File "/usr/lib64/python2.7/subprocess.py", line 541, in check_call
          raise CalledProcessError(retcode, cmd)
      CalledProcessError: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status 1 (ElasticBeanstalk::ExternalInvocationError)
    caused by: Traceback (most recent call last):
        File "/opt/python/run/venv/bin/pip", line 7, in <module>
          from pip import main
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/pip/__init__.py", line 15, in <module>
          from pip.vcs import git, mercurial, subversion, bazaar  # noqa
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/pip/vcs/mercurial.py", line 10, in <module>
          from pip.download import path_to_url
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/pip/download.py", line 38, in <module>
          from pip._vendor import requests, six
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/pip/_vendor/requests/__init__.py", line 53, in <module>
          from .packages.urllib3.contrib import pyopenssl
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/pip/_vendor/requests/packages/__init__.py", line 3, in <module>
          from . import urllib3
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/__init__.py", line 10, in <module>
          from .connectionpool import (
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 37, in <module>
          from .request import RequestMethods
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/request.py", line 6, in <module>
          from .filepost import encode_multipart_formdata
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/pip/_vendor/requests/packages/urllib3/filepost.py", line 3, in <module>
          from uuid import uuid4
        File "/opt/python/run/venv/local/lib/python3.4/site-packages/uuid.py", line 138
          if not 0 <= time_low < 1<<32L:
                                      ^
      SyntaxError: invalid syntax
      2017-06-07 19:08:18,171 ERROR    Error installing dependencies: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status 1
      Traceback (most recent call last):
        File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 22, in main
          install_dependencies()
        File "/opt/elasticbeanstalk/hooks/appdeploy/pre/03deploy.py", line 18, in install_dependencies
          check_call('%s install -r %s' % (os.path.join(APP_VIRTUAL_ENV, 'bin', 'pip'), requirements_file), shell=True)
        File "/usr/lib64/python2.7/subprocess.py", line 541, in check_call
          raise CalledProcessError(retcode, cmd)
      CalledProcessError: Command '/opt/python/run/venv/bin/pip install -r /opt/python/ondeck/app/requirements.txt' returned non-zero exit status 1 (Executor::NonZeroExitStatus)

还有我的 requirements.txt:

appdirs==1.4.3
bcrypt==3.1.3
beautifulsoup4==4.6.0
cffi==1.10.0
click==6.7
django-htmlmin==0.10.0
dominate==2.3.1
Faker==0.7.12
Flask==0.12.2
Flask-BasicAuth==0.2.0
Flask-Bcrypt==0.7.1
Flask-Bootstrap==3.3.7.1
Flask-WTF==0.14.2
html5lib==0.999999999
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
packaging==16.8
pycparser==2.17
pyparsing==2.2.0
python-dateutil==2.6.0
PyYAML==3.12
requests==2.14.2
six==1.10.0
ua-parser==0.7.3
user-agents==1.1.0
uuid==1.30
visitor==0.1.3
webencodings==0.5.1
Werkzeug==0.12.2
WTForms==2.1

我还没有 beanstalk 配置文件,但我已经手动安装了:yum install libffi-devel

我的第一个问题是我们如何确定何时需要将 -devel 包添加到我们的部署中? (我通过安装上面的 devel 包修复了第一个部署问题。) 我假设所有必要的包/库都将与 requirements.txt 一起安装?

我的第二个问题是,您对这次部署失败的原因有任何线索吗? (有望与第一个问题相关联?)

提前感谢您的帮助,

Stf

【问题讨论】:

【参考方案1】:

尝试从您的 requirements.txt 中删除以下行

uuid==1.30

uuid 从 2.5 版左右开始与 Python 捆绑在一起。

【讨论】:

嗨@Igor T.,谢谢。我刚刚试了下,还是部署失败,我也遇到了同样的错误。

以上是关于Flask Beanstalk 部署错误的主要内容,如果未能解决你的问题,请参考以下文章

如何在部署 Flask 应用程序时修复此 Elastic Beanstalk 错误:在您的系统上找不到 Python 3.7.0

尝试将 Flask 应用程序部署到 AWS Elastic Beanstalk 时,我不断收到“ModuleNotFoundError: No module named 'app'”错误消息

如何使用应用程序工厂将 Flask 应用程序部署到 AWS Elastic beanstalk

部署在 Elastic Beanstalk 上的 Python Flask 服务器出现 AWS 内部服务错误,日志说 SECRET_KEY 从未设置?

在 Elastic BeanStalk 上部署 Flask 应用程序时遇到问题

Flask 应用程序 - 部署到 AWS Elastic Beanstalk 时出错