[Python-Dev] intra-package mutual imports fail: "from <pkg> import <mod>"

Matthias Urlichs smurf@noris.de
Sun, 2 Jun 2002 06:04:59 +0200

>          module5.py:
>              from package import module6   # absolute import
>          module6.py:
>              from package import module5
>  [...]
>      ImportError: cannot import name module5
>  Is this behavior expected?  Or is it a bug?

The problem is that importing with from consists of two steps:
- load the module
- add the imported names to the local namespace

Since this addition is by reference to the actual object and not to 
the symbol's name in the other module, a concept which Python doesn't 
have (use Perl if you want this...), your recursive import doesn't 

The solution would be:
	import package.module6 as module6

which should have the same effect.
Matthias Urlichs