Attempted relative import with no known parent package

帅比萌擦擦* 提交于 2019-12-01 15:50:11

问题


from ..box_utils import decode, nms

This line is giving error

ImportError: attempted relative import with no known parent package

What is this error and how to resolve this error?


回答1:


Apparently, box_utils.py isn't part of a package. You still can import functions defined in this file, but only if the python script that tries to import these functions lives in the same directory as box_utils.py, see this answer.

Nota bene: In my case, I stumbled upon this error with an import statement with one period, like this: from .generate_holidays import generate_holidays. This syntax, however, tells Python that generate_holidays.py is part of a package, which wasn't the case. The error disappeared when I removed the period.



来源:https://stackoverflow.com/questions/55084977/attempted-relative-import-with-no-known-parent-package

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