调试隐藏“错误:无法导入名称< Name>”在Django上 [英] Debugging cryptic "Error: cannot import name <Name>" on Django

查看:90
本文介绍了调试隐藏“错误:无法导入名称< Name>”在Django上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时,当我运行 manage.py 时,我会收到一封红色的隐藏消息,表示错误:无法导入名称< Name> 而没有别的东西。

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

显然,这是一个简单的导入或语法错误,有一点环顾,我通常可以解决它。其他时候,我需要一段时间来弄明白我究竟错了什么。有没有办法让Django在这种情况下吐出更多的信息?

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?

推荐答案

这是一个令人讨厌的问题。幸运的是,它已经修复(最近):请参阅此票这个补丁

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

如果你想刚刚破解你本地的django安装(你运行在virtualenv或buildout,右边?),更改到您的django目录(具有README,INSTALL等)的根目录,并运行:

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\

所以,如果你运行django trunk> 17197,将补丁应用到你的django安装(它适用于我的django 1.2),或者等到django 1.4,你可以这样做:

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!

这篇关于调试隐藏“错误:无法导入名称&lt; Name&gt;”在Django上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆