以下是我的项目结构:
/project_dir
/src
__init__.py
index.py
/handler
__init__.py
base_handler.py
在index.py
中,我像这样导入base_handler.BaseHandler
:
from src.handler.base_handler import BaseHandler
出现错误:
ModuleNotFoundError: No module named 'src'
奇怪的是,当我将index.py
移出src
文件夹时,这个错误就会消失:
/project_dir
index.py
/src
__init__.py
/handler
__init__.py
base_handler.py
现在在index.py
中,我可以像这样导入BaseHandler
:
from src.handler.base_handler import BaseHandler
有人能告诉我为什么会这样吗
在
index.py
中,如果您像这样导入BaseHandler
,它将工作:from handler.base_handler import BaseHandler
相关问题 更多 >
编程相关推荐