Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bizarre error importing settings in django

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

like image 985
diegueus9 Avatar asked May 17 '11 20:05

diegueus9


3 Answers

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.

like image 101
mipadi Avatar answered Oct 17 '22 20:10

mipadi


If you are getting this error when trying to get started with django and appengine, whilst following the guide at http://www.allbuttonspressed.com/projects/djangoappengine

and you created symlinks to the folders, the guide is wrong whilst creating the djangoappengine symlink. You need to go 1 directory e.g.

NOT:

Copy the following folders into your project (e.g., django-testapp):

django-nonrel/django => <project>/django
djangotoolbox/djangotoolbox => <project>/djangotoolbox
django-autoload/autoload => <project>/autoload
django-dbindexer/dbindexer => <project>/dbindexer
djangoappengine => <project>/djangoappengine

FIXED:

Copy the following folders into your project (e.g., django-testapp):

django-nonrel/django => <project>/django
djangotoolbox/djangotoolbox => <project>/djangotoolbox
django-autoload/autoload => <project>/autoload
django-dbindexer/dbindexer => <project>/dbindexer
djangoappengine/djangoappengine => <project>/djangoappengine

Notice the last line.

like image 29
jmoz Avatar answered Oct 17 '22 21:10

jmoz


I hunted all thru the django code for an hour until I came across this:

manage.py [command] --traceback

Turns out there was an import error deep in my app. Once I could see the error, it took ten seconds to fix. :/

like image 32
Gringo Suave Avatar answered Oct 17 '22 21:10

Gringo Suave