From 8b3f7e3dd61629f00e146329d5829c687aa9ae2e Mon Sep 17 00:00:00 2001 From: XucroYuri Date: Tue, 7 Jul 2026 13:36:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(webui):=20=E9=A1=B6=E9=83=A8=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E4=BB=93=E5=BA=93=E6=A0=B9=E5=88=B0=20sys.path,=20?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E7=9B=B4=E6=8E=A5=E8=BF=90=E8=A1=8C=E6=AD=A4?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: 直接运行 python GPT_SoVITS/inference_webui.py 时(非经 webui.py), sys.path 无仓库根, 导致 on_model_name_change 触发时 'from tools.list_metadata import parse_list_line' 报 ModuleNotFoundError。 修复: 顶部计算仓库根(dirname(dirname(__file__))) 并 insert 到 sys.path, 与 webui.py 启动方式行为一致。对经 webui.py 启动的场景无副作用(去重判断)。 实测: proplus 工作区直接启动, 选模型->40样本+emotion 正常, 无报错。 --- GPT_SoVITS/inference_webui.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/GPT_SoVITS/inference_webui.py b/GPT_SoVITS/inference_webui.py index ae1c897a..0fb300a3 100644 --- a/GPT_SoVITS/inference_webui.py +++ b/GPT_SoVITS/inference_webui.py @@ -11,6 +11,11 @@ from __future__ import annotations import psutil import os +# 确保仓库根在 sys.path, 使 from tools.xxx 可用 (兼容直接运行此脚本或经 webui.py 启动) +_now_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if _now_dir not in __import__('sys').path: + __import__('sys').path.insert(0, _now_dir) + def set_high_priority(): """把当前 Python 进程设为 HIGH_PRIORITY_CLASS""" if os.name != "nt":