[Ubuntu Django] Could not import settings 'settings'

Posted on 2013-12-06
Last Modified: 2013-12-06
I try to install django project on Ubuntu with Apache.

Instructions can be found in article:
Sorry for russian description, but commands are onenglish so I think this article can be useful.

I am getting an error:

Fri Dec 06 07:00:51 2013] [error] [client] mod_wsgi (pid=8114): Exception occurred processing WSGI script '/var/www/debianworld_ru/deploy/django.wsgi'.
[Fri Dec 06 07:00:51 2013] [error] [client] Traceback (most recent call last):
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/core/handlers/", line 219, in __call__
[Fri Dec 06 07:00:51 2013] [error] [client]     self.load_middleware()
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/core/handlers/", line 39, in load_middleware
[Fri Dec 06 07:00:51 2013] [error] [client]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/utils/", line 184, in inner
[Fri Dec 06 07:00:51 2013] [error] [client]     self._setup()
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/conf/", line 42, in _setup
[Fri Dec 06 07:00:51 2013] [error] [client]     self._wrapped = Settings(settings_module)
[Fri Dec 06 07:00:51 2013] [error] [client]   File "/usr/local/lib/python2.7/dist-packages/Django-1.4.10-py2.7.egg/django/conf/", line 95, in __init__
[Fri Dec 06 07:00:51 2013] [error] [client]     raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Fri Dec 06 07:00:51 2013] [error] [client] ImportError: Could not import settings 'settings' (Is it on sys.path?): No module named settings

Open in new window

VirtualHost configuration:

<VirtualHost *:80>
    ErrorLog    /var/www/debianworld_ru/logs/error_log
    CustomLog   /var/www/debianworld_ru/logs/access_log common

    WSGIScriptAlias / /var/www/debianworld_ru/deploy/django.wsgi

    WSGIDaemonProcess dw-site user=dw group=dw home=/var/www/debianworld_ru/media/ \
                      processes=2 threads=4 maximum-requests=100 display-name=apache-dw-wsgi
    WSGIProcessGroup dw-site

    Alias "/media_admin/" "/usr/lib/python2.7/dist-packages/django/contrib/admin/static/"
    <Location "/media_admin/">
        SetHandler None

    Alias "/media/" "/var/www/debianworld_ru/media/"
    <Location "/media/">
        SetHandler None

Open in new window

Please let me know if you need any additional information to help me.
Thank you.
Question by:ChantingWolf
1 Comment

Accepted Solution

ChantingWolf earned 0 total points
ID: 39700813
A fix:

Aded path to settings file in file deploy/django.wsgi
sys.path.append( "/var/www/debianworld_ru/apps/apps" )

import os, sys

dn = os.path.dirname
PROJECT_ROOT = os.path.abspath( dn(dn(__file__)) )
DJANGO_PROJECT_ROOT = os.path.join(PROJECT_ROOT, 'apps')

sys.path.append( DJANGO_PROJECT_ROOT )
sys.path.append( "/var/www/debianworld_ru/apps/apps" )

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Open in new window


Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question