我的包裹结构是:
package:
-> code
---> template
------> index.html
------> scrap.html
---> main.py
---> scrape.py
---> __init__.py
-> test
---> code
-----> template
---> test_main.py
---> __init__.py
在运行python3 test/test_main.py
时
我收到以下错误消息
ModuleNotFoundError: No module named 'code.main'; 'code' is not a package
我的test_main.py有
from code.main import get_serive, list_service
我尝试使用sys.path.append(../)
的绝对路径和相对路径。还是一样的错误。
此外,我尝试检查路径print(sys.path)
->它向我显示了正确的路径package/test etc
。
因此,如果我使用from ..code.main import get_serive, list_service
,则会抛出错误ValueError: Attempted relative import beyond top-level package
那么,我该如何解决该问题?