Attempted relative import in non-package (after 2to3)

Remko picture Remko · Mar 31, 2011 · Viewed 20.5k times · Source

After converting to Python 3.x using 2to3 (see my previous question), I get this error during the build:

  File "setup.py", line 28, in <module>
    from . import mof_compiler
ValueError: Attempted relative import in non-package

The code:

from . import mof_compiler
mof_compiler._build()

But I don’t know why this is wrong, since mof_compiler is in the same dir as setup.py. Please help!

Answer

S.Lott picture S.Lott · Mar 31, 2011

Since there is no __init__.py, the working directory is a non-package.

You don't need a relative import.

Or.

You need an __init__.py to make a package.