导入包含“django”一词的包时发生名称冲突在名字里?
我有一个有点奇怪的问题。我决定将包的整个分支从 重命名为
foo.bar.somemodule
问题
foo.django.bar.somemodule
是完成此操作后,我收到以下错误:
Traceback (most recent call last):
File "/home/workspace/eclipse/foo/src/foo/manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named core.management
如果我现在,将名称恢复为
foo.djangox.bar.somemodule
IT WORKS!请注意,我在 django 一词中添加了“x”。
使用 foo.django.bar.somemodule 时似乎存在某种名称冲突,但是是什么造成的呢?它们应该与 django 本身分开。
我的代码中的所有导入均采用
from foo.django.bar.somemodule import someobject
import foo.django.bar.somemodule
编辑形式:以澄清倒数第二个导入中有一个“x”
I have a somewhat odd problem. I decided to rename an entire branch of my package from
foo.bar.somemodule
to
foo.django.bar.somemodule
The problem is after this is done, I get the following error:
Traceback (most recent call last):
File "/home/workspace/eclipse/foo/src/foo/manage.py", line 2, in <module>
from django.core.management import execute_manager
ImportError: No module named core.management
If I now, revert the name to
foo.djangox.bar.somemodule
IT WORKS! Notice, the 'x' I added to the word django.
It seems there are some kind of name clash when using foo.django.bar.somemodule, but What gives? They should be separate from django itself.
All the imports in my code are of the form
from foo.django.bar.somemodule import someobject
import foo.django.bar.somemodule
edit: to clarify there is an 'x' in the second to last import
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您遇到了想要执行绝对导入的情况,但你的 Python 版本默认情况下不会执行这些操作。在受影响的文件顶部添加 from __future__ importabsolute_import 来告诉 Python 虚拟机激活它。
You're running into a situation where you want to perform an absolute import, but your Python version doesn't do them by default. Add
from __future__ import absolute_import
at the top of the afflicted file to tell the Python VM to activate it.