Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k 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 (44.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

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...