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.
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
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:
- Login inside your ec2 instance that ebs uses.
- Go to /var/app/venv/staging-LQM1lest/bin <-- can change based on configuration(check that using ebs console).
- sudo ./pip install -r /var/app/current/requirements.txt
This should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With