【问题标题】:Django application fails to deploy on AWS ElasticBeanstalk with 'firebase-admin' libraryDjango 应用程序无法使用“firebase-admin”库在 AWS ElasticBeanstalk 上部署
【发布时间】:2020-08-01 11:50:27
【问题描述】:

我正在将我的 python/django 应用程序部署到 aws elasticbeanstalk。 如果我没有在 requirements.txt 中指定“firebase-admin”库,它会很好地部署。 但是,如果我添加“firebase-admin”,无论 requirements.txt 中的哪个版本,都无法部署,如下所示:

这是我的 requirements.txt:

Django==3.0.1
djangorestframework==3.11.0
psycopg2==2.7.3.1
django-cors-headers==3.2.0
pytz==2017.2
tinys3==0.1.12
apiclient==1.0.3
drf_yasg==1.17.1
google-api-python-client==1.7.3
google-auth==1.5.0
google-auth-httplib2==0.0.3
httplib2==0.11.3
django-rest-auth==0.9.5
oauth2client==4.1.2
geographiclib==1.50
geopy==1.20.0
numpy==1.15.2
pyyaml==5.3.1

以及 AWS elasticbeanstalk python 实例详情: 在 64 位 Amazon Linux/2.9.7 上运行的 Python 3.6

请帮忙。谢谢

更新: 以下 requirements.txt 可以在 localhost 虚拟环境中正常工作:

Django==3.0.1
djangorestframework==3.11.0
psycopg2==2.7.3.1
django-cors-headers==3.2.0
pytz==2017.2
tinys3==0.1.12
apiclient==1.0.3
drf_yasg==1.17.1
google-api-python-client==1.7.8
google-auth==1.14.0
google-auth-httplib2==0.0.3
httplib2==0.11.3
django-rest-auth==0.9.5
oauth2client==4.1.2
geopy==1.20.0
pyyaml==5.3.1
firebase-admin==2.13.0

但在部署到 AWS 时出现以下错误:

ERROR   Your requirements.txt is invalid. Snapshot your logs for details.
2020-04-22 00:14:47    ERROR   [Instance: i-0864d69c58c343870] Command failed on instance. Return code: 1 Output: (TRUNCATED)...)
  File "/usr/lib64/python2.7/subprocess.py", line 190, 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. 

完成 AWS 日志:

-------------------------------------
/var/log/eb-activity.log
-------------------------------------
          pp_opts)
        File "/usr/lib64/python3.6/distutils/unixccompiler.py", line 129, in _compile
          raise CompileError(msg)
      distutils.errors.CompileError: command 'gcc' failed with exit status 1

      During handling of the above exception, another exception occurred:

      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/tmp/pip-build-h4kd5_1k/grpcio/setup.py", line 400, in <module>
          cmdclass=COMMAND_CLASS,
        File "/opt/python/run/venv/local/lib/python3.6/site-packages/setuptools/__init__.py", line 144, in setup
          return distutils.core.setup(**attrs)
        File "/usr/lib64/python3.6/distutils/core.py", line 148, in setup
          dist.run_commands()
        File "/usr/lib64/python3.6/distutils/dist.py", line 955, in run_commands
          self.run_command(cmd)
        File "/usr/lib64/python3.6/distutils/dist.py", line 974, in run_command
          cmd_obj.run()
        File "/opt/python/run/venv/local/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in run
          return orig.install.run(self)
        File "/usr/lib64/python3.6/distutils/command/install.py", line 593, in run
          self.run_command('build')
        File "/usr/lib64/python3.6/distutils/cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "/usr/lib64/python3.6/distutils/dist.py", line 974, in run_command
          cmd_obj.run()
        File "/usr/lib64/python3.6/distutils/command/build.py", line 135, in run
          self.run_command(cmd_name)
        File "/usr/lib64/python3.6/distutils/cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "/usr/lib64/python3.6/distutils/dist.py", line 974, in run_command
          cmd_obj.run()
        File "/opt/python/run/venv/local/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 87, in run
          _build_ext.run(self)
        File "/usr/lib64/python3.6/distutils/command/build_ext.py", line 339, in run
          self.build_extensions()
        File "/tmp/pip-build-h4kd5_1k/grpcio/src/python/grpcio/commands.py", line 267, in build_extensions
          "Failed `build_ext` step:\n{}".format(formatted_exception))
      commands.CommandError: Failed `build_ext` step:
      Traceback (most recent call last):
        File "/usr/lib64/python3.6/distutils/unixccompiler.py", line 127, in _compile
          extra_postargs)
        File "/tmp/pip-build-h4kd5_1k/grpcio/src/python/grpcio/_spawn_patch.py", line 54, in _commandfile_spawn
          _classic_spawn(self, command)
        File "/usr/lib64/python3.6/distutils/ccompiler.py", line 909, in spawn
          spawn(cmd, dry_run=self.dry_run)
        File "/usr/lib64/python3.6/distutils/spawn.py", line 36, in spawn
          _spawn_posix(cmd, search_path, dry_run=dry_run)
        File "/usr/lib64/python3.6/distutils/spawn.py", line 159, in _spawn_posix
          % (cmd, exit_status))
      distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1

      During handling of the above exception, another exception occurred:

      Traceback (most recent call last):
        File "/tmp/pip-build-h4kd5_1k/grpcio/src/python/grpcio/commands.py", line 262, in build_extensions
          build_ext.build_ext.build_extensions(self)
        File "/usr/lib64/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
          self._build_extensions_serial()
        File "/usr/lib64/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
          self.build_extension(ext)
        File "/opt/python/run/venv/local/lib/python3.6/site-packages/setuptools/command/build_ext.py", line 208, in build_extension
          _build_ext.build_extension(self, ext)
        File "/usr/lib64/python3.6/distutils/command/build_ext.py", line 533, in build_extension
          depends=ext.depends)
        File "/usr/lib64/python3.6/distutils/ccompiler.py", line 574, in compile
          self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
        File "/tmp/pip-build-h4kd5_1k/grpcio/src/python/grpcio/commands.py", line 246, in new_compile
          pp_opts)
        File "/usr/lib64/python3.6/distutils/unixccompiler.py", line 129, in _compile
          raise CompileError(msg)
      distutils.errors.CompileError: command 'gcc' failed with exit status 1


      ----------------------------------------
  Command "/opt/python/run/venv/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-h4kd5_1k/grpcio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-okr6a_v3-record/install-record.txt --single-version-externally-managed --compile --install-headers /opt/python/run/venv/include/site/python3.6/grpcio" failed with error code 1 in /tmp/pip-build-h4kd5_1k/grpcio/
  You are using pip version 9.0.1, however version 20.0.2 is available.
  You should consider upgrading via the 'pip install --upgrade pip' command.
  2020-04-22 23:07:23,479 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 190, in check_call
      raise CalledProcessError(retcode, cmd)
  CalledProcessError: Command '/opt/python/run/venv/bin/pip install -r /opt/python/onde

ck/app/requirements.txt' returned non-zero exit status 1 (Executor::NonZeroExitStatus)

【问题讨论】:

  • 发帖到 Stack Overflow 时,请不要提供带文字的图片。最好将文本复制到问题本身中,并对其进行格式化,以便于准备、复制和搜索。
  • 请帮助大家,我被困在这里已经 36 小时了。
  • 我在给定的 requirements.txt 文件中看不到 firebase-admin。你是怎么指定的?
  • 是的,这就是要求,txt 有效:我向其中添加了 firebase-admin,例如:firebase-admin==4.0.0

标签: python django firebase amazon-elastic-beanstalk firebase-admin


【解决方案1】:

我在本地尝试了你的 requirements.txt 文件,结果出现以下错误。

ERROR: google-api-core 1.17.0 has requirement google-auth<2.0dev,>=1.14.0, but you'll have google-auth 1.5.0 which is incompatible.
ERROR: google-cloud-storage 1.27.0 has requirement google-auth<2.0dev,>=1.11.0, but you'll have google-auth 1.5.0 which is incompatible.
ERROR: firebase-admin 4.0.0 has requirement google-api-python-client>=1.7.8, but you'll have google-api-python-client 1.7.3 which is incompatible.

这很可能也是您的部署环境中发生的情况,只是它没有记录错误。尝试解决上述依赖冲突,然后重试。

【讨论】:

  • 首先感谢:) 我尝试过更改版本,这在 localhost 虚拟环境上运行良好,但在 AWS 上出错。我在帖子的更新标题下方添加了详细信息。请看一看。
  • 不能确定。它仍然很可能是一个依赖错误,但由于它隐藏了pip 错误日志,我们无法确定发生了什么。我还看到你降级了firebase-admin。相反,我建议将其和依赖项升级到最新版本。
  • 我降级了 firebase-admin,因为它的更高版本在虚拟环境中出现错误。我已在 COMPLETE AWS LOGS 标题下方使用 Complete AWS 日志更新了帖子。请检查:)
  • 我真的不建议这样做。请尝试使用最新的依赖项。我在上面发布的错误消息清楚地表明您还需要升级google-authgoogle-api-python-client。您的日志显示 grpcio 编译错误,这很可能发生在 Firestore 安装期间。这可能是您可以通过使用最新的依赖项来避免的事情。但如果问题继续出现,请尝试联系 AWS 社区,了解如何在 EBS 上安装 google-cloud-firestore 等软件包。
  • 一些搜索揭示了 Python+gcc+EBS 的许多类似问题。您可能会遇到类似的情况。如果升级依赖项没有帮助,请尝试 stackoverflow.com/questions/48334158/… 中的解决方法
猜你喜欢
  • 2021-10-11
  • 2019-08-20
  • 2017-08-02
  • 2020-01-11
  • 2019-02-09
  • 2017-09-24
  • 2016-11-14
  • 1970-01-01
  • 2020-03-21
相关资源
最近更新 更多