I am trying to run a Django application on AWS Elastic Beanstalk, but I am stuck with what seems to be a PYTHONPATH or virtualenv problem, and I cannot figure it out.
When I try to load a page in my browser, I get a yellow Django error screen (I'm still in debug mode):
Exception Value: No module named views.rest
Exception Location: /opt/python/current/app/project/urls.py in <module>, line 3
Python Executable: /opt/python/run/venv/bin/python
Python Version: 2.7.5
Python Path:
['/opt/python/run/venv/lib/python2.7/site-packages',
'/opt/python/current/app',
...
My urls.py resources:
from django.conf.urls import patterns, include, url
from django.contrib import admin
from myapp.views.rest import *
If I ssh into an EC2 instance, the path looks right; /opt/python/current/appcontains my application including /opt/python/current/app/myapp/views/rest.py.
My directory structure contains (there too, of course):
app/
.ebextensions/
packages.config
python.config
.elasticbeanstalk/
config
optionsettings.myapp-deployment-env
project/
settings.py
application.py
myapp/
views/
rest.py
views.py
__init__.py
In __init__.pyI have:
from myapp.views.views import *
from myapp.views.rest import *
The problem is not related to these files, but if I add another import to urls.py, this will not work either, so it does not find the application at all.
In packages.configI have:
packages:
yum:
postgresql-devel: []
python.config ( virtualenv, ?)
container_commands:
00_activate:
command: "source /opt/python/run/venv/bin/activate"
01_make_admin_executable:
command: "chmod +x scripts/createadmin.py"
leader_only: true
02_make_executable:
command: "chmod +rx application.py"
leader_only: true
03_syncdb:
command: "python manage.py syncdb --noinput"
leader_only: true
04_collectstatic:
command: "python manage.py collectstatic --noinput"
option_settings:
- option_name: AWS_SECRET_KEY
value: mykey
- option_name: AWS_ACCESS_KEY_ID
value: myaccesskeyid
- option_name: application_stage
value: "staging"
, . , PYTHONPATH ..
[aws:elasticbeanstalk:application:environment]
DJANGO_SETTINGS_MODULE=project.settings
eb update git aws.push.
! AWS, , - . , - , .