我正在尝试遵循PEP 328,使用以下目录结构:
pkg/
__init__.py
components/
core.py
__init__.py
tests/
core_test.py
__init__.py
在core_test.py中,我有以下导入语句
from ..components.core import GameLoopEvents
然而,当我运行时,我得到以下错误:
tests$ python core_test.py
Traceback (most recent call last):
File "core_test.py", line 3, in <module>
from ..components.core import GameLoopEvents
ValueError: Attempted relative import in non-package
我在搜索中找到了"relative path not working even with __init__.py"和"Import a module from a relative path",但它们没有帮助。
这里有什么我遗漏的吗?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
是的。你没有将它作为一个包使用。