如何从AWS EB(Elastic Beanstalk)Linux实例运行manage.py?
如果我从'/ opt / python / current / app'运行它,它会显示以下异常。
Traceback (most recent call last):
File "./manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
我认为这与virtualenv有关。任何提示?
答案 0 :(得分:76)
如何从AWS Elastic Beanstalk AMI运行manage.py。
sudo su -
以获得适当的权限)source /opt/python/run/venv/bin/activate
source /opt/python/current/env
cd /opt/python/current/app
python manage.py <commands>
或者,您可以运行命令,如下所示:
cd /opt/python/current/app
/opt/python/run/venv/bin/python manage.py <command>
答案 1 :(得分:1)
此答案假定您已安装EB CLI。请按照下列步骤操作:
eb ssh <environment-name>
. /opt/python/current/env
如果愿意,可以使用printenv
查看环境变量。
source /opt/python/run/venv/bin/activate
XX
)cd /opt/python/bundle/XX/app/
python manage.py <command_name>
假设您的环境名称为my-env
,最新的部署编号为13
,并且您想运行shell
命令:
eb ssh my-env # 1
. /opt/python/current/env # 2
source /opt/python/run/venv/bin/activate # 3
cd /opt/python/bundle/13/app/ # 4
python manage.py shell # 5
答案 2 :(得分:1)
使用新版本的Python,路径似乎已更改。
所以说明是:
eb shh
/var/app/venv/
检查环境的路径。唯一的文件夹应该是下一步的[KEY] /var/app/venv/[KEY]/bin/activate
激活环境python3 /var/app/current/manage.py <command>
当然,亚马逊可以随时更改它。