今天在运行Python文件时遇见了ImportError: No module named ‘util ’ 问题
问题:在trainwer.py 文件中导入了 util/utils.py 中的AnchorTargetCreator和ProposalTargetCreator模块,结果报错
原因:说明在命令中执行用例,没有把项目文件添加为环境变量。
方法:需要在代码中把项目文件夹添加为环境变量。
import os
import sys
current_directory = os.path.dirname(os.path.abspath(file))
root_path = os.path.abspath(os.path.dirname(current_directory) + os.path.sep + “.”)
sys.path.append(root_path)
Python:ImportError
最新推荐文章于 2024-07-12 16:16:27 发布