I have some example files laid out following the example given in PEP 328.

moduleX.py contains:

from .moduleY import spam
from .moduleY import spam as ham
from . import moduleY
from ..subpackage1 import moduleY
from ..subpackage2.moduleZ import eggs
from ..moduleA import foo
from ...package import bar
from ...sys import path

When I try to run that file as a top-level module, I get an exception:

C:\package\subpackage1> python moduleX.py
Traceback (most recent call last):
  File "moduleX.py", line 1, in <module>
    from .moduleY import spam
ValueError: Attempted relative import in non-package

Why does this code not work? There are __init__.py files in each directory; shouldn't this make them work as packages?

Edit
Report