简体   繁体   中英

AWS and Django: “Couldn't import Django”

I am new programming in Django. I do a local demo and it runs without problem but the next step is deploying the Django application on AWS Elastic beanstalk, I am trying that.

I have this Enviroment: ~/Python_Env/MiEntorno

And this Project: ~/ProyectosDjango/Refugio

My current Django project structure is this:

requirements.txt
.ebextensions
    |-01-django_env.config
.elasticbeanstalk
    |-config.yml
.gitignore
custom_storage.py
manage.py
Refugio
   |__init__.py
   |-settings
   |-urls.py
   |-wsgi.py
|-apps
|-templates
|-static

I have this error when i execute this command: (Mi Entorno) /ProyectosDjango/Refugio> manage.py collectstatic or manage.py runserver

"Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?"

I put this in my -01-django_env.config:

option_settings:
    "aws:elasticbeanstalk:application:environment":
    DJANGO_SETTINGS_MODULE: "Refugio.settings"
    PYTHONPATH: "/opt/python/current/app/Refugio:$PYTHONPATH"
    "aws:elasticbeanstalk:container:python"
    WSGIPath: "Refugio/Refugio/wsgi.py"

and in setting I edit the database and add this:

STATICFILES_LOCATION = 'static'
MEDIAFILES_LOCATION = 'media'

AWS_STORAGE_BUCKET_NAME = 's3.refugioprueba.com'
AWS_ACCESS_KEY_ID = 'xxx'
AWS_SECRET_ACCESS_KEY = 'yy/xxx/'

STATICFILES_STORAGE = 'custom_storages.StaticStorage'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
AWS_S3_CUSTOM_DOMAIN = '%s.s3-us-west-1.amazonaws.com' % AWS_STORAGE_BUCKET_NAME 
AWS_S3_SECURE_URLS = False 

from boto.s3.connection import ProtocolIndependentOrdinaryCallingFormat 
AWS_S3_CALLING_FORMAT = ProtocolIndependentOrdinaryCallingFormat
from boto.s3.connection import S3Connection 
S3Connection.DefaultHost = 's3.us.west-1.amazonaws.com'

STATIC_URL = "http://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION) 
MEDIA_URL = "http://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION ) 


WSGI_APPLICATION = 'Refugio.wsgi.application'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'ebdb',
        'USER': 'root',
        'PASSWORD': 'XXX',
        'HOST': 'XXXrds.amazonaws.com',
        'PORT': 3306, 
    }
}

Are you sure it's installed in the environment? As in pip install django (or whichever specific version you are using)? Or alternatively pip install -r requirements.txt if it's in your requirements.txt file? EBS usually automatically installs requirements.txt dependencies so placing it there is the safest

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