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!
Relative imports use dot(.) notation to specify a location. Single dot specifies that the module is in the current directory, two dots indicate that module is in its parent directory of the current location and three dots indicate that it is in grandparent directory and so on.
That is, if a module is in a package, __package__ is set to the package name to enable explicit relative imports. Specifically: When the module is a package, its __package__ value should be set to its __name__ .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With