How to resolve “ValueError: attempted relative import beyond top-level package”

左心房为你撑大大i 提交于 2019-11-29 12:52:45

It seems to me, that without adding pkg to my PATH it is impossible to import modules from sub2 in sub1. Here is explanation why:

Relative imports use a module's name attribute to determine that module's position in the package hierarchy. If the module's name does not contain any package information (e.g. it is set to 'main') then relative imports are resolved as if the module were a top level module, regardless of where the module is actually located on the file system.

Here is official python web site, where it is explained

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