[New-bugs-announce] [issue8389] Incomprehensibly import error

Torsten Landschoff report at bugs.python.org
Wed Apr 14 01:19:18 CEST 2010

New submission from Torsten Landschoff <t.landschoff at gmx.net>:

I ran into an ImportError I was unable to explain:

$ python -c "import a.b"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "a/b/__init__.py", line 1, in <module>
    import a.b.c
  File "a/b/c.py", line 2, in <module>
    import a.b.t as t
AttributeError: 'module' object has no attribute 'b'

This is the source code:
$ tail `find -name \*.py`
==> ./demo.py <==
import a.b

==> ./a/__init__.py <==

==> ./a/b/c.py <==
# Does not work:
import a.b.t as t
# Works:
# import a.b
# from a.b import t

==> ./a/b/t.py <==

==> ./a/b/__init__.py <==
import a.b.c
# Works:
# import a.b.t

Replacing any import with one of the versions annotated as working fixes it. Stripping another level from the package tree fixes it as well. Why!?

components: Interpreter Core
files: import_error.tar.gz
messages: 103091
nosy: torsten
severity: normal
status: open
title: Incomprehensibly import error
versions: Python 2.6
Added file: http://bugs.python.org/file16915/import_error.tar.gz

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list