[Django]-ImportError: Could not import settings

34👍

The error says ImportError: Could not import settings 'bookings.settings' (Is it on sys.path?): No module named unipath

So, is your path /Users/django_demo/godjango/bookings within the python-sys.path?

Check it in your shell with:

$ python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:52:43) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for path in sys.path: print path
... 

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/suds-0.4-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.6-intel.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL-1.1.7-py2.7-macosx-10.6-intel.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/spyne-2.8.2_rc-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml-3.0alpha2-py2.7-macosx-10.6-intel.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pytz-2012d-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_debug_toolbar-0.9.4-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_social_auth-0.7.7-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/python_openid-2.2.5-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/oauth2-1.5.211-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Django-1.4.1-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/httplib2-0.7.6-py2.7.egg
/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
/Library/Python/2.7/site-packages
>>> 

If not – you need to add it or simply move your bookings app into one of the paths represented in your sys.path

14👍

Modify your wsgi.py file from

 import os
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bookings.settings")
 from django.core.wsgi import get_wsgi_application
 application = get_wsgi_application()

to

import os, sys    
sys.path.append(' /Users/Sreek/django_demo/godjango/bookings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bookings.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
👤kta

11👍

The significant part of the traceback here is right at the very end. It says “No module named unipath”. You’ve referred to that somewhere in your code, but you don’t seem to have it in your project – it’s not part of the standard library, so you’ll need to install it somewhere that Python can see it.

4👍

Alternatively, you can even pass the settings path at run time like so:

python manage.py syncdb --settings=bookings.settings --pythonpath=/Users/django_demo/godjango/bookings

This should override the environment variable (DJANGO_SETTINGS_MODULE)

1👍

Review hour /etc/apache2/httpd.conf file; you must include the WSGIPythonPath directive, to indicate the folder which contains your Django project (manage.py file), like:

WSGIPythonPath /home/user/Projects/Django/MyProject

also if you used some weird port in your VirtualHost, specify if for listening:

Listen 90

Hope this helps somebody

👤Chimo

1👍

ImportError: Could not import settings 'settings' (Is it on sys.path? Is there an import error in the settings file?): No module named setting

In my case I was using __init__.py to import other files and there was an error in it, so settings might actually exist but be flawed.

👤cbron

Leave a comment