Forums

(COMMON ERROR): Error running WSGI application ImportError: No module named 'munichliving.settings'

Hello,

the error I am getting is identical to the one faced by many.

(My understanding is that my wsgi.py file is identical to the one displayed in this post:)

https://www.pythonanywhere.com/forums/topic/13032/


    import os
    import sys

   #BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
   #sys.path.append(BASE_DIR)

   # assuming your Django settings file is at '/home/myusername/mysite/mysite/settings.py'

     path = '/home/KamiBarut/munichliving'

    if path not in sys.path:
             sys.path.insert(0, path)
            #sys.path.append(path)
            #sys.path.append("/home/KamiBarut/munichliving")

   os.environ["DJANGO_SETTINGS_MODULE"] = "munichliving.settings"

    from django.core.wsgi import get_wsgi_application 
    application = get_wsgi_application()

  #import os
  #import sys
  #BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  #sys.path.append(BASE_DIR)
  #os.environ['DJANGO_SETTINGS_MODULE'] = 'munichliving.settings'
  #os.environ.setdefault("DJANGO_SETTINGS_MODULE", "munichliving.settings")

Thanks,

K.

See our help page for debugging that: http://help.pythonanywhere.com/pages/DebuggingImportError/

I followed the debugging steps outlined on https://help.pythonanywhere.com/pages/DebuggingImportError

>>> import sys
>>> print('\n'.join(sys.path))

/home/KamiBarut/.virtualenvs/mysite-virtualenv/lib/python35.zip
/home/KamiBarut/.virtualenvs/mysite-virtualenv/lib/python3.5
/home/KamiBarut/.virtualenvs/mysite-virtualenv/lib/python3.5/plat-linux
/home/KamiBarut/.virtualenvs/mysite-virtualenv/lib/python3.5/lib-dynload
/usr/lib/python3.5
/usr/lib/python3.5/plat-linux
/home/KamiBarut/.virtualenvs/mysite-virtualenv/lib/python3.5/site-packages

( My filepath: /home/KamiBarut/munichliving/munichliving/settings.py )

>>> import munichliving.settings
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'munichliving.settings'
>>>

Any ideas what the problem could be ?

Thanks, K.

The most important part is this: Take the path you add to sys.path and add the DJANGO_SETTINGS_MODULE variable with .s replaced with /s and add .py. So in your example, it would be "/home/KamiBarut/munichliving" + "munichliving.settings" => "/home/KamiBarut/munichliving/munichliving/settings.py". Then make sure that there is a file that exists in your file storage that mathces that path exactly including case.

I am only following word for word the debugging steps outlined on the page https://help.pythonanywhere.com/pages/DebuggingImportError/ , not trying to reinvent the wheel or anything. You will notice that settings is pluralized everywhere on that page and that the .py extension is NOT added where the array is defined, i.e:

os.environ["DJANGO_SETTINGS_MODULE"] = "myproject.settings"

(wsgi.py file)

    import os
    import sys
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    sys.path.append(BASE_DIR)

    #path = '/home/KamiBarut/munichliving'
    path = '/home/KamiBarut/munichliving/munichliving/settings.py'

    if path not in sys.path:
        sys.path.insert(0, path)
        #sys.path.append('/home/KamiBarut/munichliving')
        #sys.path.append(path)
        #sys.path.append("/home/KamiBarut/munichliving")
     os.environ['DJANGO_SETTINGS_MODULE'] = 'munichliving.settings.py'
    #os.environ['DJANGO_SETTINGS_MODULE'] = 'munichliving.settings'
    #os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'munichliving.settings')

    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()

    #import os
    #import sys
    #BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    #sys.path.append(BASE_DIR)
    #os.environ['DJANGO_SETTINGS_MODULE'] = 'munichliving.settings'
    #os.environ.setdefault("DJANGO_SETTINGS_MODULE", "munichliving.settings")

Any other ideas ?

[edited by admin: formatting]

your path should probably be something like '/home/KamiBarut/munichliving/'