开发者

Nameclash when importing packages that has the word 'django' in the name?

开发者 https://www.devze.com 2023-03-07 18:25 出处:网络
I have a somewhat odd problem. I decided to rename an entire branc开发者_JS百科h of my package from

I have a somewhat odd problem. I decided to rename an entire branc开发者_JS百科h 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号