Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'django

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.

like image 553
dcarlo56ave Avatar asked Oct 29 '25 19:10

dcarlo56ave


2 Answers

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
like image 53
Bejür Avatar answered Nov 01 '25 08:11

Bejür


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.

like image 37
bor Avatar answered Nov 01 '25 09:11

bor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!