diff --git a/.gitignore b/.gitignore index 4eed81a..6d45e4b 100644 --- a/.gitignore +++ b/.gitignore @@ -398,3 +398,5 @@ FodyWeavers.xsd /.cache/ /workspace/ *.pt + +/python/ diff --git a/README.md b/README.md index 00b29c4..9aac7cd 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ powershell -ExecutionPolicy Bypass -File tools/Setup-Python.ps1 -Sam2 # CPU 环境附加 -Cpu ``` -程序优先使用本项目 `.venv/Scripts/python.exe`,也可在「设置」填写已有 PartTrainer 的 Python 完整路径来复用环境。相机预览和录像不需要 Python。设置保存在 `workspace/settings.json`,录像默认保存在 `workspace/recordings`;API Key 不保存到配置或日志。原 PartTrainer 的 `project.json` 可直接打开,项目中原有的绝对视频、权重路径需要仍然有效。集成后的源码、Python worker 和安装脚本均在本仓库内,构建与发布无需 PartTrainer 目录。 +程序固定使用可执行文件同目录的 `python/python.exe`,不读取系统 PATH 或设置文件中的 Python 路径,界面不提供路径设置。安装脚本将完整运行时及依赖放在仓库 `python/`,构建和发布会携带该目录。相机预览和录像不需要 Python。设置保存在 `workspace/settings.json`,录像默认保存在 `workspace/recordings`;API Key 不保存到配置或日志。原 PartTrainer 的 `project.json` 可直接打开,项目中原有的绝对视频、权重路径需要仍然有效。集成后的源码、Python worker 和安装脚本均在本仓库内,构建与发布无需 PartTrainer 目录。 相机录像窗口以模态打开;SOP 正在运行或操作相机时会提示先停止,避免两个流程同时占用设备。关闭采集窗口会结束并封装录像。关闭主窗口时会取消后台 Python 任务、等待进程退出并释放相机;即使已切回 SOP 页面也会清理。 @@ -134,7 +134,7 @@ dotnet run --project tests/Training.Smoke dotnet run --project tests/Training.UiSmoke dotnet run --project tests/Training.CameraSmoke dotnet run --project tests/Training.ShellSmoke -.venv/Scripts/python.exe -X utf8 -m unittest discover -s tests -p test_worker.py -v +python/python.exe -X utf8 -m unittest discover -s tests -p test_worker.py -v ``` ## 配方 diff --git a/src/SopHelper.App/SopHelper.App.csproj b/src/SopHelper.App/SopHelper.App.csproj index ae4e5ab..f18c1b7 100644 --- a/src/SopHelper.App/SopHelper.App.csproj +++ b/src/SopHelper.App/SopHelper.App.csproj @@ -34,6 +34,7 @@ + diff --git a/src/SopHelper.App/Training/MainViewModel.cs b/src/SopHelper.App/Training/MainViewModel.cs index 59e129d..8d6ac12 100644 --- a/src/SopHelper.App/Training/MainViewModel.cs +++ b/src/SopHelper.App/Training/MainViewModel.cs @@ -68,7 +68,7 @@ public sealed class MainViewModel : BindableBase } } // Configuration is saved locally, except the API key which is passed only through the worker environment. - public string Python { get; set; } = "python"; + private static string PythonPath => Path.Combine(AppContext.BaseDirectory, "python", "python.exe"); public string Label { get; set; } = "零件"; public int ExtractStride { get; set; } = 1; public int MaxFrames { get; set; } = 600; @@ -111,8 +111,6 @@ public sealed class MainViewModel : BindableBase var directory = new DirectoryInfo(AppContext.BaseDirectory); while (directory.Parent != null && !File.Exists(Path.Combine(directory.FullName, "SopHelper.slnx"))) directory = directory.Parent; Root = File.Exists(Path.Combine(directory.FullName, "SopHelper.slnx")) ? directory.FullName : AppContext.BaseDirectory; - var localPython = Path.Combine(Root, ".venv", "Scripts", "python.exe"); - if (File.Exists(localPython)) Python = localPython; LoadSettings(); ImportCommand = Command(Import); OpenCommand = Command(() => @@ -278,7 +276,9 @@ public sealed class MainViewModel : BindableBase try { SaveSettings(); - await _worker.RunAsync(Python.Trim(), Path.Combine(Root, "tools", "worker.py"), request, line => + if (!File.Exists(PythonPath)) + throw new FileNotFoundException("缺少内置 Python 环境,请运行 tools/Setup-Python.ps1 -Sam2 后重新构建程序。", PythonPath); + await _worker.RunAsync(PythonPath, Path.Combine(Root, "tools", "worker.py"), request, line => { try { @@ -345,7 +345,7 @@ public sealed class MainViewModel : BindableBase { Directory.CreateDirectory(Path.Combine(Root, "workspace")); File.WriteAllText(Path.Combine(Root, "workspace", "settings.json"), JsonSerializer.Serialize(new - { Python, Checkpoint, SamConfig, Device, ExportEvery, Epochs, Batch, ImageSize, Model, TrainingOutputDirectory, Endpoint, ApiModel, Description, ExtractStride, MaxFrames })); + { Checkpoint, SamConfig, Device, ExportEvery, Epochs, Batch, ImageSize, Model, TrainingOutputDirectory, Endpoint, ApiModel, Description, ExtractStride, MaxFrames })); } private void LoadSettings() { diff --git a/src/SopHelper.App/Training/TrainingPage.xaml b/src/SopHelper.App/Training/TrainingPage.xaml index 8aa17b3..26248b1 100644 --- a/src/SopHelper.App/Training/TrainingPage.xaml +++ b/src/SopHelper.App/Training/TrainingPage.xaml @@ -52,8 +52,6 @@ - -