我正在尝试在 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'
这是一个问题,我无法正确设置我的环境。一些人四处搜寻发现了enum34
模块是问题的原因,但是当我尝试 ssh 进入我的 EB 环境并使用以下命令将其删除时:
/opt/python/run/venv/bin/pip3 uninstall enum34
我得到同样的错误,表明 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: []
数据库迁移.config
container_commands:
01_migrate:
command: "./manage.py migrate"
leader_only: true
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: yahoo_serp.settings
该问题是由使用 Python3.6 的 AWS Elastic Beanstalk 引起的,由于某种原因,在“eb deploy”上,pip 忽略了 setup.py 的限制:
install_requires = [
'enum34>1.1.0;python_version<"3.4"',
]
并尝试安装 enum34 。
我使用的解决方法是创建一个预部署挂钩,该挂钩将在部署期间 pip install -rrequirements.txt 之后立即删除 enum34 软件包和分发信息。
为了达成这个:
- 在 eb 扩展文件夹中创建一个文件。
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
- 提交更改并运行 eb-deploy。文件
uninstall_enum34.sh
将创建在/opt/elasticbeanstalk/hooks/appdeploy/pre/
文件夹,该文件夹将在预部署期间运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)