Forums

Loading Django settings - missing module

Hi I have a Django app in /home/pguyard/MWC_APP

My settings file is in /home/pguyard/MWC_APP/MWC_APP/settings/local_dev.py

My wsgi file is configured like so:

project_home = u'/home/pguyard/MWC_APP'
if project_home not in sys.path:
sys.path.insert(0, project_home)
os.environ['DJANGO_SETTINGS_MODULE'] = 'MWC_APP.settings.local_dev'

I am running a virtual env. The casing is all ok. I still get

Error running WSGI application
ImportError: No module named local_dev

I can import the settings file in the Python shell (in MWC_APP:>>>import MWC_APP.settings.local_dev works). If I run

python /home/pguyard/MWC_APP/MWC_APP/settings/local_dev.py

I get an error:

File "/home/pguyard/MWC_APP/MWC_APP/settings/local_dev.py", line 1, in <module>
from MWC_APP.settings.base import *
ImportError: No module named MWC_APP.settings.base

(base.py are my base settings imported into local_dev.py).

I can't figure out what the issue is, but I am new to this... Any ideas?? Thanks

We have a help page that describes how Python finds the modules that you import and can help with debugging: http://help.pythonanywhere.com/pages/DebuggingImportError/

I have tried everything in those docs I think, except checking what directory is in sys.path. How would I do that? Thanks

Just add print(sys.path) before the os.environ line in your WSGI file, then run the python command in a bash console again and see what it prints out.

One possibility -- if the directory /home/pguyard/ appears before /home/pguyard/MWC_APP in the system path that is printed out, then it might be looking in /home/pguyard/MWC_APP/settings/ for base.py instead of in /home/pguyard/MWC_APP/MWC_APP