Bizarre error importing settings in django

diegueus9 picture diegueus9 · May 17, 2011 · Viewed 10.9k times · Source

I have many projects working in ubuntu with python2.7 and virtualenv/virtualenvwrapper, in my work some developers works with macosx and windows, generally I create the project as usual:

django-admin.py start project x

And we use svn for cvs, but in some point, without nothing rational for me, when I try something like:

python manage.py runserver

doesn't work, but is just for me and is in my laptop, that doesn't happens in productions servers or another developers.

any ideas?

I got this error:

Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've customized things. You'll have to run django-admin.py, passing it your settings module. (If the file settings.py does indeed exist, it's causing an ImportError somehow.)

But obviously, the settings file exists and is in the same folder of manage.py file, and doesn't work just for me...

This happens too with django and appengine

Answer

mipadi picture mipadi · May 17, 2011

I got this error:

Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've customized things. You'll have to run django-admin.py, passing it your settings module. (If the file settings.py does indeed exist, it's causing an ImportError somehow.)

The manage.py script prints that warning whenever an import error occurs, so if your settings.py module imports stuff and that causes an import error, manage.py will still print that warning.

One way to diagnose would be to (temporarily) change manage.py from

#!/usr/bin/env python
from django.core.management import execute_manager
try:
    import settings # Assumed to be in the same directory.
except ImportError:
    import sys
    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
    sys.exit(1)

if __name__ == "__main__":
    execute_manager(settings)

to

#!/usr/bin/env python
from django.core.management import execute_manager
import settings # Assumed to be in the same directory.

if __name__ == "__main__":
    execute_manager(settings)

and see the stack trace that is printed when running $ python manage.py runserver.