From 913b4f5431a0826ed4646962bf2a65481cb3846d Mon Sep 17 00:00:00 2001 From: Kenichiro NOGI Date: Sun, 2 Aug 2026 11:19:47 +0900 Subject: [PATCH] =?UTF-8?q?fix:=207-Zip=E3=81=8CPATH=E6=9C=AA=E7=99=BB?= =?UTF-8?q?=E9=8C=B2=E3=81=A7=E3=82=82=E6=A8=99=E6=BA=96=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=83=BC=E3=83=AB=E5=A0=B4=E6=89=80=E3=81=8B?= =?UTF-8?q?=E3=82=89=E8=A6=8B=E3=81=A4=E3=81=91=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 実機実行時、7-ZipはインストールされているがPATHに7zコマンドが無くFileNotFoundErrorで失敗したため、 C:\Program Files\7-Zip\7z.exe 等へのフォールバック探索を追加。 Co-Authored-By: Claude Sonnet 5 --- PythonProj/ScanOCR/build/build_package.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/PythonProj/ScanOCR/build/build_package.py b/PythonProj/ScanOCR/build/build_package.py index 6e9db456..00e026c5 100644 --- a/PythonProj/ScanOCR/build/build_package.py +++ b/PythonProj/ScanOCR/build/build_package.py @@ -105,6 +105,24 @@ def setup_python(script_dst: Path, tmp_dir: Path) -> None: ) +SEVEN_ZIP_FALLBACK_PATHS = ( + r"C:\Program Files\7-Zip\7z.exe", + r"C:\Program Files (x86)\7-Zip\7z.exe", +) + + +def find_7zip_exe() -> str: + found = shutil.which("7z") + if found: + return found + for candidate in SEVEN_ZIP_FALLBACK_PATHS: + if Path(candidate).exists(): + return candidate + raise RuntimeError( + "7-Zip(7z.exe)が見つかりません。PATHに通すか、標準的な場所にインストールしてください。" + ) + + def setup_tesseract(script_dst: Path, tmp_dir: Path) -> None: tools_dst = script_dst / "tools" / "tesseract" tools_dst.mkdir(parents=True) @@ -112,10 +130,11 @@ def setup_tesseract(script_dst: Path, tmp_dir: Path) -> None: installer_path = tmp_dir / "tesseract-setup.exe" download(TESSERACT_INSTALLER_URL, installer_path) + seven_zip_exe = find_7zip_exe() extract_dir = tmp_dir / "tesseract-extract" extract_dir.mkdir() subprocess.run( - ["7z", "x", str(installer_path), f"-o{extract_dir}", "-y"], + [seven_zip_exe, "x", str(installer_path), f"-o{extract_dir}", "-y"], check=True, ) for item in extract_dir.iterdir():