简体   繁体   中英

ImportError: No module named django.core.wsgi in Elastic Beanstalk

I was getting started with AWS' Elastic Beanstalk .

I am following this tutorial to deploy a Django/PostgreSQL app .

I did everything before the 'Configuring a Database' section. The deployment was also successful but I am getting an Internal Server Error.

Here's the traceback from the logs:

 mod_wsgi (pid=30226): Target WSGI script '/opt/python/current/app/polly/wsgi.py' cannot be loaded as Python module.
[Tue Sep 15 12:06:43.472954 2015] [:error] [pid 30226] [remote 172.31.14.126:53947] mod_wsgi (pid=30226): Exception occurred processing WSGI script '/opt/python/current/app/polly/wsgi.py'.
[Tue Sep 15 12:06:43.474702 2015] [:error] [pid 30226] [remote 172.31.14.126:53947] Traceback (most recent call last):
[Tue Sep 15 12:06:43.474727 2015] [:error] [pid 30226] [remote 172.31.14.126:53947]   File "/opt/python/current/app/polly/wsgi.py", line 12, in <module>
[Tue Sep 15 12:06:43.474777 2015] [:error] [pid 30226] [remote 172.31.14.126:53947]     from django.core.wsgi import get_wsgi_application
[Tue Sep 15 12:06:43.474799 2015] [:error] [pid 30226] [remote 172.31.14.126:53947] ImportError: No module named django.core.wsgi

Any idea what's wrong?

Have you created a requirements.txt in the root of your application? Elastic Beanstalk will automatically install the packages from this file upon deployment. (Note it might need to be checked into source control to be deployed.)

pip freeze > requirements.txt

(You will probably want to do that from within a virtualenv so that you only pick up the packages your app actually needs to run. Doing that with your system Python will pick up every package you've ever installed system-wide.)

The answer ( https://stackoverflow.com/a/47209268/6169225 ) by carl-g is correct. One thing that got me was that requirements.txt was in the wrong directory. Let's say you created a django project called mysite . This is the directory in which you run the eb command(s) --> make sure requirements.txt is in this directory.

If you forget the .ebextensions folder you will get the same error.

I was following along with a good simple (non Elastic Beanstalk) tutorial and missed step 3 & 4 of Elastic Beanstalk .

I was using Django 1.11 and Python 2.7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM