[Fixed]-ImportError: No module named mysite.settings (Django)

6👍

The problem was in the include path:

import sys
#Wrong!
#sys.path.append("/home/user/mysite/mysite")

#Correct
sys.path.append("/home/user/mysite")
👤u123

19👍

Add this to your wsgi.py file:

path = '/home/path/to/project'
if path not in sys.path:
    sys.path.append(path)

before setting

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")

19👍

Please try:

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'] = 'YOURAPP.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "YOURAPP.settings")

This is working for scripts in main project directory, as well.

👤porto

1👍

I had this error too, when I was trying to move a windows project to Debian.

import sys
sys.path.append("your project path")

0👍

Also, if you are using Visual Studio, check that your app properties for Django match the settings module that you are expecting. By default, it is set to $(MSBuildProjectName).settings, which was a problem for me since my project name and app name were not the same.

You can find this setting by right clicking on your app in the Solution Explorer and clicking on “Properties” and then the Django tab on the left.

👤Dima

Leave a comment