Elastic Beanstalk 中的 enum34 问题

Gre*_*dot 4 python django pip amazon-web-services

我正在尝试在 Elastic Beanstalk 中设置 django 环境。当我尝试通过 requirements.txt 文件进行安装时,我遇到了 python3.6 问题。

File "/opt/python/run/venv/bin/pip", line 4, in <module>
  import re
File "/opt/python/run/venv/lib64/python3.6/re.py", line 142, in <module>
  class RegexFlag(enum.IntFlag):
 AttributeError: module 'enum' has no attribute 'IntFlag'
Run Code Online (Sandbox Code Playgroud)

当这是一个问题时,我无法正确设置我的环境。一些搜索将enum34模块确定为问题的原因,但是当我尝试通过 ssh 进入我的 EB 环境并使用以下方法将其删除时:

/opt/python/run/venv/bin/pip3 uninstall enum34
Run Code Online (Sandbox Code Playgroud)

我得到同样的错误,表明 venv 以某种方式损坏。我该如何解决这个问题?以下是我传入环境中的扩展文件以供参考:

django.config:

    option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: yahoo_serp/wsgi.py
  aws:autoscaling:launchconfiguration:
    InstanceType: t2.large
packages:
    yum:
        libjpeg-turbo-devel: []
Run Code Online (Sandbox Code Playgroud)

db-migrate.config

container_commands:
  01_migrate:
    command: "./manage.py migrate"
    leader_only: true
option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: yahoo_serp.settings
Run Code Online (Sandbox Code Playgroud)

Far*_*orn 6

该问题是由使用 Python3.6 的 AWS Elastic Beanstalk 引起的,出于某种原因,在“eb deploy”上,pip 忽略了限制 setup.py:

install_requires = [
'enum34>1.1.0;python_version<"3.4"',
]
Run Code Online (Sandbox Code Playgroud)

并尝试安装 enum34 无论如何。

我使用的解决方法是创建一个预部署挂钩,它将在部署期间 pip install -r requirements.txt 后立即删除 enum34 包和分发信息。

为达到这个:

  1. 在 eb 扩展文件夹中创建一个文件。 00_fix_enum.config
  2. 将以下内容放在文件中:
files:
 "/opt/elasticbeanstalk/hooks/appdeploy/pre/uninstall_enum34.sh":
   mode: "000755"
   owner: root
   group: root
   content: |
     rm -f -r /opt/python/run/venv/lib/python3.6/site-packages/enum && rm -f -r /opt/python/run/venv/lib/python3.6/site-packages/enum34-1.1.10.dist-info
Run Code Online (Sandbox Code Playgroud)
  1. 提交您的更改并运行 eb-deploy。该文件uninstall_enum34.sh将在/opt/elasticbeanstalk/hooks/appdeploy/pre/文件夹中创建,然后在预部署期间运行。

  • 我只是想更新它已经对我有用了。所以问题是脚本执行的顺序。我在您的脚本之前运行了 `/opt/elasticbeanstalk/hooks/appdeploy/pre` 中的另一个脚本,这些脚本使用 `pip` 并失败。因此,为了解决这个问题,我只是将您的脚本重命名为“00uninstall_enum34.sh”以使其首先运行。 (2认同)