How to run manage.py
from AWS EB (Elastic Beanstalk) Linux instance?
If I run it from '/opt/python/current/app', it shows the below exception.
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
I think it's related with virtualenv. Any hints?
How to run manage.py from AWS Elastic Beanstalk AMI.
eb ssh
)
sudo su -
to have proper permissions) source /opt/python/run/venv/bin/activate
source /opt/python/current/env
cd /opt/python/current/app
python manage.py <commands>
Or, you can run command as like the below:
cd /opt/python/current/app
/opt/python/run/venv/bin/python manage.py <command>
With the new version of Python paths seem to have changed.
So the instructions are:
eb shh
/var/app/venv/
. The only folder should be the [KEY]
for the next stepsource /var/app/venv/[KEY]/bin/activate
python3 /var/app/current/manage.py <command>
Of course Amazon can change it anytime.
This answer assumes you have installed EB CLI . Follow these steps:
eb ssh <environment-name>
. /opt/python/current/env
If you wish you can see the environment variables using printenv
.
source /opt/python/run/venv/bin/activate
XX
)cd /opt/python/bundle/XX/app/
python manage.py <command_name>
Asumming that your environment name is my-env
, your latest deployment number is 13
, and you want to run the shell
command:
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
As of February 2022 the solution is as follows:
$ eb ssh
$ sudo su -
$ export $(cat /opt/elasticbeanstalk/deployment/env | xargs)
$ source /var/app/venv/*/bin/activate
$ python3 /var/app/current/manage.py <command name>
$ export $(cat /opt/elasticbeanstalk/deployment/env | xargs) is needed to import your environment variables if you have a database connection (most likely you will)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.