Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging cryptic "Error: cannot import name <Name>" on Django

Tags:

django

Sometimes when I run manage.py I get a cryptic message in red that says Error: cannot import name <Name> and nothing else.

Obviously, this is a simple import or syntax error and with a little looking around, I can usually fix it. Other times however it takes me quite a while to figure out what exactly I did wrong. Is there a way to get Django to spit out more info in this situation?

like image 984
Conley Owens Avatar asked Jun 22 '10 03:06

Conley Owens


1 Answers

This is an annoying problem. Luckily, it's been fixed (recently): see this ticket and this patch.

If you want to just hack your local django install (you're running under virtualenv or buildout, right?), change to the root of your django directory (the one with README, INSTALL, etc) and run this:

curl "https://code.djangoproject.com/changeset/17197?format=diff&new=17197" | patch -p3\

So, if you run django trunk > 17197, apply the patch to your django install (it applied to django 1.2 for me), or wait until django 1.4, you'll be able to do this:

./manage.py shell --traceback

And you'll get a full traceback instead of just the Error: cannot import ...

Voila!

like image 194
easel Avatar answered Sep 30 '22 13:09

easel