ImportError: Could not import settings

853 views
Skip to first unread message

sri

unread,
Oct 20, 2012, 6:44:24 AM10/20/12
to django...@googlegroups.com
Hi,

I am trying to develop an sample project in Django and getting errors when i run syncdb command.

This is how my project structure looks like:

/Users/Sreek/django_demo/godjango/bookings:
                      
                       manage.py
                       registration/
                             forms.py
                             views.py
                             models.py
                             urls.py
                       bookings/
                             settings.py
                             urls.py

And my manage.py file looks like below :

    #!/usr/bin/env python
    import os
    import sys

    if __name__ == "__main__":
        os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bookings.settings")
        from django.core.management import execute_from_command_line
         execute_from_command_line(sys.argv)

And my PYTHONPATH and DJANGO_SETTINGS_MODULE are set as below

$echo $DJANGO_SETTINGS_MODULE
bookings.settings

$ echo $PYTHONPATH
/Users/Sreek/django_demo/godjango/bookings

And my WSGI.py file looks like below:

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


But when i run the python manage.py syncdb command, i am getting the following error.

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/core/management/sql.py", line 6, in <module>
    from django.db import models
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
    if DEFAULT_DB_ALIAS not in settings.DATABASES:
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/Sreekanth/django_demo/godjango/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'bookings.settings' (Is it on sys.path?): No module named unipath



Could someone suggest what i am missing?  Thanks in Advance.

Tomas Ehrlich

unread,
Oct 20, 2012, 7:03:04 AM10/20/12
to django...@googlegroups.com
Hello,
there's a little hint at the end of exception:

> No module named unipath

Seems like you import module unipath in your settings.py, which is not
on your sys.path.

I never set PYTHONPATH for development and everything works fine.
Python adds current directory to sys.path, so when you run ./manage.py,
you don't need to set PYTHONPATH pointing to current working directory.

Check content of you sys.path.


Cheers,
Tom

sri

unread,
Oct 20, 2012, 7:47:33 AM10/20/12
to django...@googlegroups.com
Hi Tom,

Thanks very much.That solved the problem after removing that import.

Sreekanth
Reply all
Reply to author
Forward
0 new messages