问题: - PyInstaller在分析阶段尝试导入torch/transformers等ML库 - 这些库与Python 3.13不兼容,导致"Windows fatal exception: access violation" - 构建过程无法完成,无法生成exe文件 解决方案: 1. 添加pyi_hooks/pyi_rth_ignore_torch.py运行时hook - 在PyInstaller分析阶段阻止torch等模块的导入 - 这些模块将在运行时动态安装 2. 添加pyi_hooks/hook-exclude-ml.py和hook-paddleocr.py - 明确告诉PyInstaller不收集这些ML库 3. 更新build.bat和build.sh - 使用--runtime-hook和--additional-hooks-dir - 添加--exclude-module参数排除所有ML库 测试: - 验证所有hook文件语法正确 - 验证项目核心功能可以在不导入torch的情况下正常工作 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
107 lines
2.9 KiB
Batchfile
107 lines
2.9 KiB
Batchfile
@echo off
|
|
REM ================================
|
|
REM CutThenThink Windows Build Script
|
|
REM ================================
|
|
|
|
REM Change to project directory
|
|
cd /d "%~dp0"
|
|
|
|
REM Check Python
|
|
echo Checking Python...
|
|
python --version 2>nul
|
|
if errorlevel 1 (
|
|
echo Python not found. Please install Python 3.8+
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
REM Get Python version
|
|
for /f "tokens=2" %%i in ('python --version 2^>^&1') do set PYVER=%%i
|
|
echo Detected Python %PYVER%
|
|
|
|
echo.
|
|
echo 1/5. Installing PyInstaller...
|
|
python -m pip install --user pyinstaller 2>nul
|
|
|
|
echo.
|
|
echo 2/5. Installing dependencies (compatible with Python 3.13)...
|
|
REM Use SQLAlchemy 2.0.36+ for Python 3.13 compatibility
|
|
python -m pip install --user "sqlalchemy>=2.0.36" 2>nul
|
|
python -m pip install --user "PyQt6>=6.7.0" 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
|
|
|
|
REM Install build dependencies
|
|
python -m pip install --user setuptools 2>nul
|
|
|
|
echo.
|
|
echo 3/5. Cleaning previous build...
|
|
if exist build rmdir /s /q build
|
|
if exist dist rmdir /s /q dist
|
|
|
|
echo.
|
|
echo 4/5. Building executable...
|
|
echo NOTE: Using custom hooks to exclude heavy ML libraries that cause Python 3.13 issues
|
|
echo These will be installed dynamically at runtime if needed
|
|
python -m PyInstaller ^
|
|
--noconfirm ^
|
|
--name "CutThenThink" ^
|
|
--windowed ^
|
|
--onefile ^
|
|
--add-data "src:src" ^
|
|
--runtime-hook=pyi_hooks/pyi_rth_ignore_torch.py ^
|
|
--additional-hooks-dir=pyi_hooks ^
|
|
--hidden-import=PyQt6.QtCore ^
|
|
--hidden-import=PyQt6.QtGui ^
|
|
--hidden-import=PyQt6.QtWidgets ^
|
|
--hidden-import=sqlalchemy ^
|
|
--hidden-import=sqlalchemy.orm ^
|
|
--hidden-import=PIL ^
|
|
--hidden-import=PIL.Image ^
|
|
--hidden-import=PIL.ImageEnhance ^
|
|
--hidden-import=PIL.ImageFilter ^
|
|
--hidden-import=numpy ^
|
|
--hidden-import=pyperclip ^
|
|
--hidden-import=tkinter ^
|
|
--hidden-import=tkinter.ttk ^
|
|
--hidden-import=tkinter.scrolledtext ^
|
|
--hidden-import=tkinter.messagebox ^
|
|
--hidden-import=yaml ^
|
|
--hidden-import=requests ^
|
|
--collect-all pyqt6 ^
|
|
--exclude-module=torch ^
|
|
--exclude-module=transformers ^
|
|
--exclude-module=tensorflow ^
|
|
--exclude-module=onnx ^
|
|
--exclude-module=onnxruntime ^
|
|
--exclude-module=sentencepiece ^
|
|
--exclude-module=tokenizers ^
|
|
--exclude-module=diffusers ^
|
|
--exclude-module=accelerate ^
|
|
--exclude-module=datasets ^
|
|
--exclude-module=huggingface_hub ^
|
|
--exclude-module=safetensors ^
|
|
src/main.py
|
|
|
|
if errorlevel 1 (
|
|
echo.
|
|
echo ================================
|
|
echo Build Failed!
|
|
echo ================================
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo.
|
|
echo ================================
|
|
echo Build Complete!
|
|
echo Executable: dist\CutThenThink.exe
|
|
echo File size: ~30-50 MB
|
|
echo ================================
|
|
echo.
|
|
echo On first run, app will auto-download and install PaddleOCR.
|
|
echo.
|
|
pause
|