PyWart: "Python's import statement and the history of external dependencies"

Ian Kelly ian.g.kelly at
Fri Nov 21 18:42:44 CET 2014

On Fri, Nov 21, 2014 at 9:12 AM, Tim Chase
<python.list at> wrote:
> The only time I've been stung by name overloading is in the indirect
> case of creating a local file and then importing smtplib
> only to have things break in unforeseen ways.  If smtplib used
> relative imports for $STDLIB/ I suspect it would ameliorate
> that particular issue for me.

Relative imports are based on package namespaces and can only be done
within a package. There's no way to do a relative import from a
separate top-level package, whether they happen to be found in the
same directory or not.

$ mkdir p1
$ touch p1/
$ echo 'from ..p2 import m2' > p1/
$ mkdir p2
$ touch p2/
$ touch p2/
$ python3 -c 'import p1.m1'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/ikelly/p1/", line 1, in <module>
    from ..p2 import m2
ValueError: attempted relative import beyond top-level package

More information about the Python-list mailing list