 <p>I have filed <a href="http://bugs.python.org/issue25294" rel="nofollow">an issue</a> against Python. The text of this issue is reproduced below:</p> <p>PEP 8 recommends absolute imports over relative imports, and section 5.4.2 of the import documentation says that an import will cause a binding to be placed in the imported module's parent's namespace.</p> <p>However, since (with all current Python versions) this binding is not made until <em>after</em> the module body has been executed, there are cases where relative imports will work fine but absolute imports will fail. Consider the simple case of these five files:</p> <pre><code>xyz.py: import x x/__init__.py: import x.y x/y/__init__.py: import x.y.a x/y/a/__init__.py: import x.y.b; foo = x.y.b.foo x/y/b/__init__.py: foo = 1 </code></pre> <p>This will fail in a fashion that may be very surprising to the uninitiated. It will not fail on any of the import statements; rather it will fail with an AttributeError on the assignment statement in x.y.a, because the import of y has not yet finished, so y has not yet been bound into x.</p> <p>This could conceivably be fixed in the import machinery by performing the binding before performing the exec. Whether it can be done cleanly, so as not to cause compatibility issues with existing loaders, is a question for core maintainers.</p> <p>But if it is decided that the current behavior is acceptable, then at a minimum both the PEP 8 and the import documentation should have an explanation of this corner case and how it can be solved with relative imports.</p>