[Django]-ImportError: Could not import settings (Is it on > sys.path? Is there an import error in the settings file?) on AWS Elastic Beanstalk

4👍

I fixed it by adding the project path to sys.path on the wsgi.py itself. Maybe you can try so.

0👍

Try modifying the DJANGO_SETTINGS_MODULE value in wsgi.py and .ebextenstions/myproject.config to be myproject.settings.active.

0👍

Even though I was also able to solve the settings import problem with Andres answer and the follow up comments by Unoti –>

To use the wsgi as produced by django (in my case 1.9), add this to the wsgi file:

sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(__file__))))

I found this to be an interesting read that still seems relevant:

Secondly, that wsgi.py was auto generated, it gave users the
impression that it would always be correct, must be used and wouldn’t
need modifying. Consequence was that people stopped seeing what one of
the main roles of the WSGi script file was for, which was to set
environment variables before the Django application got loaded.
…from: https://gist.github.com/GrahamDumpleton/b380652b768e81a7f60c

2. So since we are no longer assuming that the location and contents of the wsgi file are set in stone for production another option would be to copy your wsgi file outside of the project and simply change the settings module path address setting.

ps.
I will mention, even though this probably won’t work for you since you don’t have access to an apache configuration (?), but (for those who do,) you can use the ‘python-path’ configuration via:

WSGIDaemonProcess example.com python-home=/path/to/venv python-path=/path/to/mysite.com

Leave a comment