Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
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 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 shell

I get:

  File "", line 3, in <module>

    from import execute_from_command_line

ImportError: No module named

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 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 !

Browse Categories