Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named myapp.settings

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    
like image 223
RHPT Avatar asked Sep 15 '25 04:09

RHPT


2 Answers

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'
like image 161
conrad Avatar answered Sep 17 '25 20:09

conrad


Maybe if you put an empty

__init__.py

in the same folder as the settings.py it worked for me

like image 23
Damien Verkerk Avatar answered Sep 17 '25 20:09

Damien Verkerk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!