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
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:
00_fix_enum.config
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
uninstall_enum34.sh
will be created in the /opt/elasticbeanstalk/hooks/appdeploy/pre/
folder which will then run during the pre deploymentment.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With