ImportError: No module named myapp.settings

RHPT picture RHPT · Jan 2, 2016 · Viewed 9k times · Source

I created a Django app locally, and I would like to host it on PythonAnywhere.com. I've followed the directions at https://help.pythonanywhere.com/pages/VirtualEnvForNewerDjango and created a virtualenv with 1.9 installed. However, when I try to run my app, I get the error ImportError: No module named myapp.settings

Here is my username_pythonanywhere_com_wsgi.py

import os
import sys

# add your project directory to the sys.path
project_home = u'/home/rhpt'
if project_home not in sys.path:
    sys.path.append(project_home)

# set environment variable to tell django where your settings.py is
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'

# serve django via WSGI
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

I also tried myapp.my_app.settings without success.

My tree

myapp                                                                                                                                 
├── my_app                                                                                                                            
│   ├── __init__.py                                                                                                                        
│   ├── settings.py                                                                                                                        
│   ├── urls.py                                                                                                                            
│   └── wsgi.py                                                                                                                            
├── get_data                                                                                                                               
│   ├── __init__.py                                                                                                                        
│   ├── admin.py                                                                                                                           
│   ├── models.py                                                                                                                          
│   ├── tests.py                                                                                                                           
│   ├── urls.py                                                                                                                            
│   └── views.py                                                                                                                           
└── manage.py    

Answer

conrad picture conrad · Jan 3, 2016

if your settings.py file is in /home/rhpt/myapp/my_app/settings.py

then this part

# add your project directory to the sys.path 
project_home = u'/home/rhpt'

needs to be

# add your project directory to the sys.path 
project_home = u'/home/rhpt/myapp'

and also keep this

os.environ['DJANGO_SETTINGS_MODULE'] = 'my_app.settings'