Good Idea
Good Idea

Reputation: 2831

gunicorn "configuration cannot be imported"

I'm migrating a project that has been on Heroku to a DO droplet. Install went smoothly, and everything is working well when I python manage.py runserver 0.0.0.0:8000.

I'm now setting up gunicorn using these instructions: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04

I activate the virtual environment, and then try --bind 0.0.0.0:3666 myproject.wsgi:application. I get the following error:

Traceback (most recent call last):
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 515, in spawn_worker
    worker.init_process()
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 122, in init_process
    self.load_wsgi()
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 130, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
    __import__(module)
  File "/var/www/myproject/myproject/wsgi.py", line 6, in <module>
    from configurations.wsgi import get_wsgi_application
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/configurations/wsgi.py", line 3, in <module>
    importer.install()
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/configurations/importer.py", line 54, in install
    importer = ConfigurationImporter(check_options=check_options)
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/configurations/importer.py", line 73, in __init__
    self.validate()
  File "/var/www/myproject/venv/local/lib/python2.7/site-packages/configurations/importer.py", line 122, in validate
    raise ImproperlyConfigured(self.error_msg.format(self.namevar))
ImproperlyConfigured: Configuration cannot be imported, environment variable DJANGO_CONFIGURATION is undefined.

My wsgi.py looks like this:

# -*- coding: utf-8 -*-

import os

from configurations.wsgi import get_wsgi_application

application = get_wsgi_application()

I didn't set up the project initially, so I'm not sure what is different, or where to look.

Upvotes: 3

Views: 842

Answers (1)

Prakhar Trivedi
Prakhar Trivedi

Reputation: 8526

Use this link and Set the DJANGO_CONFIGURATION environment variable to the name of the class you just created, e.g. in bash:

export DJANGO_CONFIGURATION=Dev

Read further here.

And/or here.

Upvotes: 1

Related Questions