2

i have what seems to be a basic path problem, but i can't figure this out for the life of me.

I have the following directory structure:

    └── rockitt
        ├── activities
        │   ├── migrations
        │   ├── templates
        │   │   └── activities
        │   └── templatetags
        ├── blog
        │   ├── settings

within blog/settings I have: base.py dev.py __init.py__

__init.py__ within the directory above contains: from .dev import *

When running things like manage.py i receive the following error:

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

What I have tried so far:

  1. I've checked what paths are present when manage.py is running and the following path is at the top of the list: rockitt lib/python2.7/Django-1.7.7-py2.7.egg lib/python2.7 [other dirs...] ENV/lib/python27.zip ENV/lib/python2.7 ENV/lib/python2.7/plat-linux2 ENV/lib/python2.7/lib-tk ENV/lib/python2.7/lib-old ENV/lib/python2.7/lib-dynload /usr/local/lib/python2.7 /usr/local/lib/python2.7/plat-linux2 /usr/local/lib/python2.7/lib-tk ENV/lib/python2.7/site-packages

  2. I've tried to manually load the settings file with no luck: from the blog/settings directory i have tried (I'm not sure if this is the right way to test this however based on reading this:

    >>> import dev
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "dev.py", line 1, in <module>
        from .base import *
    ValueError: Attempted relative import in non-package
    

I'm kinda stuck on this. I -=think=- it might be also related to my wsgi.py file (below).

Further info:

  1. wsgi.py:

    import os, sys, site
    site.addsitedir('/home/thisUserName/webapps/dev_django_rockitt/ENV/lib/python2.7/site-packages')
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blog.settings.dev")
    activate_this =     os.path.expanduser("/home/thisUserName/webapps/dev_django_rockitt/ENV/bin/activate_this.py")
    execfile(activate_this, dict(__file__=activate_this))
    
    #calculate the path based on the location of the WSGI script
    project = '/home/thisUserName/webapps/dev_django_rockitt/rockitt'
    workspace = os.path.dirname(project)
    sys.path.append(workspace)
    sys.path = ['/home/thisUserName/webapps/dev_django_rockitt/rockitt/blog', '/home/thisUserName/webapps/dev_django_rockitt/rockitt'$
    
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()
    
  2. Stacktrace:

    Traceback (most recent call last):
      File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
      File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
      File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/core/management/__init__.py", line 345, in execute
    settings.INSTALLED_APPS
      File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/conf/__init__.py", line 46, in __getattr__
    self._setup(name)
      File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/conf/__init__.py", line 42, in _setup
    self._wrapped = Settings(settings_module)
      File "/home/thisUserName/webapps/dev_django_rockitt/lib/python2.7/Django-1.7.7-py2.7.egg/django/conf/__init__.py", line 98, in __init__
    % (self.SETTINGS_MODULE, e)
    ImportError: Could not import settings 'blog.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named settings
    
Community
  • 1
  • 1
AndrewO
  • 1,105
  • 4
  • 16
  • 33
  • Is the $ at the end of the sys.path line in wsgi.py just a copy-n-paste error? – devinformatics Apr 01 '15 at 22:33
  • it is - didn't catch the whole line - that's a small mistake compared to the idiocy (my own) i'm about to put in as the solution for me! good spot ;) – AndrewO Apr 01 '15 at 22:36

1 Answers1

7

it's almost tempting to remove this question due to my own stupidity, however i think the answer might help someone else who is coding and lacks sleep.

it's quite simple really - it was a typo within the blog/settings directory.

I had typed __init.py__, but obviously it should have been __init__.py

Once this was rectified the error disappeared.

I hope this helps someone in the future. Facepalm moment.

AndrewO
  • 1,105
  • 4
  • 16
  • 33