6

This is the error I get in my Apache error log:

[Sun Aug 22 16:52:06 2010] [error] [client 127.0.0.1] ImportError: No module named settings

This is my .wsgi file, per this blog post:

import sys

sys.path.insert(0, '/home/wot/django-projects/aedo')
import settings
import django.core.management
django.core.management.setup_environ(settings)
utility = django.core.management.ManagementUtility()
command = utility.fetch_command('runserver')
command.validate()
import django.conf
import django.utils

django.utils.translation.activate(django.conf.settings.LANGUAGE_CODE)

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

I've double and triple checked the path name, and that is indeed the path to my project file. I've been trying to get this to work for hours, and have done much googling. I'm asking here as my last resort. I'm desperate!

EDIT: I'm aware that there are similar questions here on SA, and I've read through most all of them, to no avail

7
  • There's a fair chance that Django can find your settings file, but it cannot import it. Django gives this error whenever it can't import a settings file for whatever reason. So try adding an import settings in your .wsgi file. Commented Aug 23, 2010 at 0:57
  • Are you 100% sure that you didn't make a typo in the path or anything? And you do actually have a settings.py in the /home/wot/django-projects/aedo directory? One or the other has to be false. Commented Aug 23, 2010 at 1:36
  • He does have 'import settings' in his WSGI file already. He isn't relying on DJANGO_SETTINGS_MODULE environment variable method. Commented Aug 23, 2010 at 1:51
  • Try typing the first three lines from the above into the python interpreter on the console. Does it work? Commented Aug 23, 2010 at 2:12
  • If doing a test with command line Python, you need to be doing it as Apache user, ensuring that personal user environment, eg PYTHONPATH variables etc, aren't being inherited across a sudo. You also should do it while current working directory is '/'. This better approximates what happens under Apache. Commented Aug 23, 2010 at 2:22

4 Answers 4

2

What is the output from running:

ls -las /home/wot/django-projects/aedo/

Is the directory and all the files readable to user that Apache runs as? If they aren't you may get that error.

Also watch talk and look at slides mentioned at:

http://blog.dscpl.com.au/2010/06/sydney-pycon-modwsgi-talk-slides.html

as it discusses permissions issues further.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah all the files are readable and executable to all users. And thanks will do
2

It doesn't work when you put:

import os, sys
sys.path.append('/usr/local/django')    # obs: path to django
sys.path.append('/home/wot/django-projects/aedo')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

in your django.wsgi file?

2 Comments

That wouldn't work as you added the site directory to sys.path and not the parent directory.
@Graham Dumpleton - true, corrected. It's because I copied from one of my projects using pydev and usually I have 2 times the directory (1 for project name and 1 for src) like .../django-projects/aedo/aedo/files.py
2

try changing

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

to

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

Actually I was getting this error too and I did the above. I also changed

ROOT_URLCONF =  'appname.urls' 

to

ROOT_URLCONF =  'urls' 

I hope your settings.py is in the same directory as the wsgi file for this project.

Comments

0

For me I had weird import issues, Python claimed Django could not import Site... Because my install went from a purely "python runserver..." to a WSGI environment, the permissions was actually a problem.

Surprised as I didn't even change the permission on the django.contrib.site package, just all of the project's files to 755.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.