运行 main.py 时出现“ValueError: Attempted relative import in non-package”错误。下面是我的文件夹结构。请帮助我,我很困惑。另外,尝试了这篇文章https://docs.python.org/3/tutorial/modules.html “6.4.2. Intra-package References”
test(folder) which has below files
|--> __init__.py
|--> a.py
|--> b.py
|--> main.py
一个.py
def test():
print('hi')
b.py
def testing():
print('helo')
主文件
from . import a,b
a.test()
b.testing()
错误:
回溯(最近一次调用):文件“main.py”,第 1 行,来自 . import a,b ValueError: Attempted relative import in non-package