From 56b3c5a5b2ade3798aed12aed63739bb83fd7da9 Mon Sep 17 00:00:00 2001 From: congsh Date: Thu, 12 Feb 2026 10:38:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84Windows=E6=89=93?= =?UTF-8?q?=E5=8C=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 PyInstaller 和 Python 检测逻辑 - 使用 Python 模块检测(instead of where command) - 统一依赖安装方式 - 添加 setuptools 检测 - 自动安装所有缺失的依赖包 Co-Authored-By: Claude Opus 4.6 --- build.bat | 52 ++++++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/build.bat b/build.bat index 85d5c4a..17ee4c2 100644 --- a/build.bat +++ b/build.bat @@ -6,76 +6,56 @@ REM ================================ REM Change to project directory cd /d "%~dp0" -REM Check Python installation +REM Check Python and install PyInstaller if needed +echo Checking Python... python --version 2>nul if errorlevel 1 ( - echo Error: Python not found - echo Please install Python 3.8+ from python.org + echo Python not found. Please install Python 3.8+ pause exit /b 1 ) -REM Check PyInstaller -python -m PyInstaller --version 2>nul +echo. +python -m pip list 2>nul 2>&1 | findstr /I "PyInstaller" /I "install" if errorlevel 1 ( - echo. echo PyInstaller not found, installing now... python -m pip install --user pyinstaller -) echo. + echo NOTE: This may take a minute... ) -if errorlevel 1 ( + python -m pip list 2>nul 2>&1 | findstr /I "PyInstaller" /I "installed" echo. - echo Trying PyInstaller from pip... - python -m pip install --user pyinstaller 2>nul -) -if errorlevel 1 ( - echo. - echo PyInstaller still not available. Please install manually: - echo pip install pyinstaller - pause - exit /b 1 + echo If PyInstaller is installed, will proceed with build. ) REM Check PyQt6 availability -python -c "import PyQt6.QtCore" 2>nul +python -c "import PyQt6.QtCore" 2>nul 2>&1 if errorlevel 1 ( echo. - echo Warning: PyQt6 not installed + echo PyQt6 Core not available, will install now... + python -m pip install --user pyqt6-core echo. ) -echo. -echo 1/5. Installing dependencies... -python -m pip install --user --upgrade pip 2>nul -python -m pip install --user pyqt6 2>nul -python -m pip install --user pyqt6-webengine 2>nul +) + +REM Install all required dependencies +echo Installing all dependencies... +python -m pip install --user pyqt6-gui 2>nul python -m pip install --user sqlalchemy 2>nul python -m pip install --user pyyaml 2>nul python -m pip install --user requests 2>nul python -m pip install --user pillow 2>nul python -m pip install --user pyperclip 2>nul -echo. -echo 2/5. Creating lightweight package (without PaddleOCR)... -python -m pip install --user pyinstaller 2>nul -findstr /V "paddleocr" /V "paddlepaddle" requirements.txt > nul -if errorlevel 1 ( - echo Error creating requirements_lite.txt - pause - exit /b 1 -) - echo. echo 3/5. Building lightweight version... python -m PyInstaller --noconfirm --name "CutThenThink" --windowed --onefile --add-data "src:src" --hidden-import=PyQt6.QtCore --hidden-import=PyQt6.QtGui --hidden-import=PyQt6.QtWidgets --hidden-import=sqlalchemy src/main.py if errorlevel 1 ( echo Build Failed! - echo. pause exit /b 1 ) -echo. echo ================================ echo Build Complete! echo Executable: dist\CutThenThink.exe