Django Shell No module named settings
I had a similar problem, where the same error was being returned when I tried to run
django-admin.py startproject myapp
.
A previous answer here helped me figure it out. The problem was that I had previously pointed DJANGO_SETTINGS_MODULE
to a certain file, which I had later deleted. To fix it, I just removed the pointer with this command:
export DJANGO_SETTINGS_MODULE=
Somehow, if your project folder is the same name as the app that has the settings file in it, and if you have __init__.py
in the project root folder, it will mess wsgi. I really dont understand why but removing this file solved this for me.
It seems the path to your project isn't being recognized by wsgi. This has happened to me, and to solve it I added this to the top of my .wsgi file:
import os
import sys
root_path = os.path.abspath(os.path.split(__file__)[0])
sys.path.insert(0, os.path.join(root_path, 'project_name'))
sys.path.insert(0, root_path)
This can happen if your root directory name is the same as the name of one of your apps. For example here I have a directory called bar
containing a Django project with an app also called bar
:
Simons-MacBook-Pro ~/temp
$ cd bar
Simons-MacBook-Pro ~/temp/bar
$ ./manage.py shell
Error: Could not import settings 'bar.settings' (Is it on sys.path?): No module named settings
Simons-MacBook-Pro ~/temp/bar
$ ls -l
total 48
-rw-r--r-- 1 simon staff 0 25 Oct 10:46 __init__.py
-rw-r--r-- 1 simon staff 130 25 Oct 10:46 __init__.pyc
drwxr-xr-x 7 simon staff 238 25 Oct 10:46 bar
-rwxr-xr-x 1 simon staff 503 25 Oct 10:46 manage.py
-rw-r--r-- 1 simon staff 5025 25 Oct 10:46 settings.py
-rw-r--r-- 1 simon staff 2658 25 Oct 10:46 settings.pyc
-rw-r--r-- 1 simon staff 556 25 Oct 10:46 urls.py
Changing the root directory's name to foo
(or anything else other than bar
) solves the problem:
Simons-MacBook-Pro ~/temp/bar
$ cd ..
Simons-MacBook-Pro ~/temp
$ mv bar foo
Simons-MacBook-Pro ~/temp
$ cd foo
Simons-MacBook-Pro ~/temp/foo
$ ./manage.py shell
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>