# -*- coding: utf-8 -*- """修 build_exe.ps1 里被搞坏的两行。 上一版用 PowerShell 内联 Python,$windows 被 PowerShell 先插值成了空, 续行符的反引号也丢了,导致脚本直接语法错误。 这里改成独立脚本文件,不受 PowerShell 插值影响。 """ from __future__ import annotations import sys from pathlib import Path TARGET = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\windows" r"\build_exe.ps1") BACKTICK = "`" GOOD_LINES = [ f' --version-file (Join-Path $windows "version_info.txt") {BACKTICK}\n', f' --noupx {BACKTICK}\n', ] def main() -> int: lines = TARGET.read_text(encoding="utf-8").splitlines(keepends=True) out = [] removed = 0 inserted = False for line in lines: stripped = line.strip() # 删掉上次插坏的两行 if stripped.startswith("--version-file") or stripped.startswith("--noupx"): removed += 1 continue out.append(line) if (not inserted) and "PIL._tkinter_finder" in line: out.extend(GOOD_LINES) inserted = True if not inserted: print(" [失败] 没找到 PIL._tkinter_finder 锚点") return 1 TARGET.write_text("".join(out), encoding="utf-8") print(f" 删掉坏行 {removed} 行,插入正确行 {len(GOOD_LINES)} 行") # 打印确认 print() for i, line in enumerate(TARGET.read_text(encoding="utf-8").splitlines()): if 24 <= i + 1 <= 38: print(f" {i + 1}: {line}") return 0 if __name__ == "__main__": sys.exit(main())