import pathlib import sys def setup_project_path(project_name='cls_train'): cur_path = pathlib.Path(__file__).parent.resolve() while cur_path.name != project_name: cur_path = cur_path.parent if cur_path.name != project_name: raise ValueError(f"找不到项目根目录: {project_name}") sys.path.append(str(cur_path)) return cur_path