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

回眸只為那壹抹淺笑 提交于 2019-12-30 05:55:09

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/5497951/attempted-relative-import-in-non-package-after-2to3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!