4

I have built a site in virtual env using django and have followed the steps from AWS document for deploying the site. I have deployed my site to AWS web server using Elastic Beanstalk and have setup a python environment running 3.6 and django 2.1.1. I have pulled the logs and am getting the following error:

Traceback (most recent call last):
File "/opt/python/current/app/weddingProject/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'
Target WSGI script '/opt/python/current/app/weddingProject/wsgi.py' cannot be loaded as Python module.

I have read other posts and they are saying that django is not installed however, the requirements.txt file does have it listed as a package to install. So I am not sure whats causing the issue and I dont know how to check the server to ensure it is installed.

When I run pip freeze > requirements.txt I do see django listed as a package to install. I run eb deploy and for some reason django is not being installed.

dcarlo56ave
  • 253
  • 5
  • 18
  • "...I am not sure whats causing the issue" - the module not being installed is causing the issue, obviously. The installation process is described in the docs for Django. I suppose AWS also provides various installation manuals. – ForceBru Oct 03 '18 at 15:46
  • have you tried installing django manually and checking it works when you do that or not? – Léopold Houdin Oct 03 '18 at 15:46
  • Yes, Django probably isn't installed. This might help: https://stackoverflow.com/a/10429168/5548239 – Dan Swain Oct 03 '18 at 15:46
  • Eh... requirements.txt lists Django, but did you actually run the install command to install the packages in requirements.txt. – Mad Wombat Oct 03 '18 at 15:56
  • @ForceBru obviously it did not install but why is what I am trying to figure out. Followed the instructions from the aws doc. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html – dcarlo56ave Oct 03 '18 at 15:59
  • @MadWombat where in the docs does it tell you that you need to run a command? I am using eb cli when I run eb deploy with the requirements.txt file thats how its knows what packages to install. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html – dcarlo56ave Oct 03 '18 at 16:01
  • You said you installed it on an AWS server. Now you are saying you are using ElasticBeanstalk. If you don't tell us what environment you are working in how can we help? – Mad Wombat Oct 03 '18 at 16:07
  • @LéopoldHoudin I ssh into the webserver but AWS does not allow you to install django via command line as I already tried this. You have to use the the eb command that creates a text file with the packages to install. – dcarlo56ave Oct 03 '18 at 16:07
  • @MadWombat bro relax its my first time doing this on AWS. I will update my post. – dcarlo56ave Oct 03 '18 at 16:09
  • That said, in the guide for using Django with EB, it clearly says you need to install Django using pip command under "Set Up a Python Virtual Environment with Django" https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html – Mad Wombat Oct 03 '18 at 16:09
  • @MadWombat correct and my project was built in django in my virtual env its is installed! – dcarlo56ave Oct 03 '18 at 16:12
  • Which AMI are you using? I had the same issue some time ago and I had to start using Ubuntu instead of Amazon's own AMI. – juanmhidalgo Oct 03 '18 at 17:58

5 Answers5

5

I had same problem. File requirements.txt were in one level deeper than it should be. Place the requirements.txt in the same directory as .elasticbeanstalk/

Example:

├── .ebextensions
│   ├── 01_packages.config
│   └── 02_python.config
├── .elasticbeanstalk
│   └── config.yml
├── testproject
│   ├── db.sqlite3
│   ├── cust_app
│   │   ├── admin.py
│   │   ├── apps.py
│   │   ├── models.py
│   │   ├── tests.py
│   │   ├── urls.py
│   │   └── views.py
│   ├── manage.py
│   └── testproject
│       ├── asgi.py
│       ├── __init__.py
│       ├── settings.py
│       ├── urls.py
│       └── wsgi.py
└── requirements.txt
Bejür
  • 110
  • 2
  • 7
  • 1
    For those who are struggling if this, also check if you are zipping inside the project folder or outside the project folder, the zip file when opened or unzipped should be similar as this solution – Luiz Oct 22 '21 at 22:21
2

Not sure why but the elasticbeanstalk did not install the requirements. It had for me too, so I had to do that manually. The appropriate way to install requirements in the proper environment would be to:

  1. Login inside your ec2 instance that ebs uses.
  2. Go to /var/app/venv/staging-LQM1lest/bin <-- can change based on configuration(check that using ebs console).
  3. sudo ./pip install -r /var/app/current/requirements.txt

This should work.

bor
  • 2,211
  • 4
  • 22
  • 37
0

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-django.html

  1. Create an environment and deploy you application to it with eb create: eb create django-env

Have you created virtual environment ? if yes, what output you get for the command eb status.

Or can you list out the steps you have followed to deploy Django app using Elastic Beanstalk ?

Read this documentation : https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-container.html to use the AWS Elastic Beanstalk Python Platform.

Shakeel
  • 1,869
  • 15
  • 23
0

I had the exact same issue. For me, I needed to put my .elasticbeanstalk with its config.yml within mysite/. Then it worked. The WSGIPath should be mysite/wsgi.py, not mysite/mysite/wsgi.py.

siowy
  • 238
  • 1
  • 2
  • 11
-1

Found the issue. The requirement.txt file was place in the wrong directory causing Django not to install.

dcarlo56ave
  • 253
  • 5
  • 18