enum34 issue in Elastic Beanstalk

2020-07-18 11:35发布

问题:

I'm trying to set up a django environment in Elastic Beanstalk. I am running into a python3.6 issue when I try to install through a requirements.txt file.

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'

I cannot set up my environment properly while this is an issue. Some searching around pinpointed the enum34 module as the cause of the issue, but when I try to ssh into my EB environment and remove it using:

/opt/python/run/venv/bin/pip3 uninstall enum34

I get the same error, indicating the venv is broken in some way. How do I get around this issue? here are the extension files I pass into the environment for reference:

django.config:

    option_settings:
  aws:elasticbeanstalk:container:python:
    WSGIPath: yahoo_serp/wsgi.py
  aws:autoscaling:launchconfiguration:
    InstanceType: t2.large
packages:
    yum:
        libjpeg-turbo-devel: []

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

回答1:

I had the same issue, solved it by removing django-enumfields from the requirements. The most important part is to rebuild the Elastic Beanstalk environment after the change.

If you still want to use enum34 package, try to use enum-compat (and rebuild the Elastic Beanstalk).



回答2:

The issue is caused by AWS Elastic Beanstalk with Python3.6, for some reason, on "eb deploy", pip ignores the restriction setup.py:

install_requires = [
'enum34>1.1.0;python_version<"3.4"',
]

and tries to install enum34 regardless.

The workaround I used was to create a pre-deployment hook which will delete the enum34 package and distribution info immediately after pip install -r requirements.txt during deployment.

To achieve this:

  1. Create a file in your eb extensions folder. 00_fix_enum.config
  2. Put the following content on the file:
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
  1. Commit your changes and run eb-deploy. The file uninstall_enum34.sh will be created in the /opt/elasticbeanstalk/hooks/appdeploy/pre/ folder which will then run during the pre deploymentment.