0 votes
1 view
in AWS by (18.2k points)

I deployed my Django app on Elastic Beanstalk, but my commands are failing and I think that the problem is that django-admin.py is not in the $PYTHONPATH, I would like to add my app to the python path, but I don't know what is the exact path on the EC2 instance. Actually I found it under: /opt/python/bundle/3/app (I used "find" command via SSH)… but is that a fixed and reliable path??

if I cd to /opt/python/bundle/3/app/myappname and run:

python manage.py shell

I get:

  File "manage.py", line 3, in <module>

    from django.core.management import execute_from_command_line

ImportError: No module named django.core.management

1 Answer

0 votes
by (42.4k points)

Amazon Beanstalk uses a virtualenv and in order to activate it you have to:

source /opt/python/run/venv/bin/activate

cd /opt/python/current/app

python manage.py commandname

Add the Python path and environment variables used by your application. So, do this:

vi /home/ec2-user/.bash_profile

and added:

export PYTHONPATH=$PYTHONPATH:/opt/python/current/app

In order to automatically activate the virtualenv and to be able to use the Django shell as soon as logged via ssh, is it possible to add:

As soon as you logged via ssh, you can automatically activate the virtualenv and the Django shell adding this to the .bash_profile:

source /opt/python/run/venv/bin/activate

cd /opt/python/current/app

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...