FIX: bundle scipy submodules (ansari_swilk_stats) + librosa .pyi stubs (lazy_loader) trong engine.spec
This commit is contained in:
+13
-2
@@ -3,7 +3,7 @@
|
|||||||
# -*- mode: python ; coding: utf-8 -*-
|
# -*- mode: python ; coding: utf-8 -*-
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from PyInstaller.utils.hooks import collect_dynamic_libs, collect_submodules
|
from PyInstaller.utils.hooks import collect_dynamic_libs, collect_submodules, collect_data_files
|
||||||
|
|
||||||
# Native DLL cho pedalboard va soundfile
|
# Native DLL cho pedalboard va soundfile
|
||||||
binaries = collect_dynamic_libs('pedalboard')
|
binaries = collect_dynamic_libs('pedalboard')
|
||||||
@@ -25,12 +25,23 @@ datas = [
|
|||||||
(os.path.join(_SPEC_ROOT, 'md'), 'md'), # /ai-prompt-generator
|
(os.path.join(_SPEC_ROOT, 'md'), 'md'), # /ai-prompt-generator
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# librosa 0.11 dùng lazy_loader.attach_stub -> lúc RUNTIME cần file .pyi
|
||||||
|
# ton tai tren disk ('Cannot load imports from non-existent stub ...librosa\__init__.pyi').
|
||||||
|
# PyInstaller mac dinh KHONG bundle .pyi -> phai collect explicit.
|
||||||
|
datas += collect_data_files('librosa', includes=['**/*.pyi'])
|
||||||
|
|
||||||
|
# scipy >= 1.18 tach scipy.stats thanh nhieu module con (vd
|
||||||
|
# _ansari_swilk_statistics) import lazy ben trong ham -> hook scipy cua
|
||||||
|
# PyInstaller miss -> ModuleNotFoundError luc runtime. Collect toan bo
|
||||||
|
# submodules cua scipy de khong sot module nao (stats/signal/ndimage...).
|
||||||
|
_scipy_hidden = collect_submodules('scipy')
|
||||||
|
|
||||||
a = Analysis(
|
a = Analysis(
|
||||||
['desktop_engine.py'],
|
['desktop_engine.py'],
|
||||||
pathex=[_SPEC_ROOT],
|
pathex=[_SPEC_ROOT],
|
||||||
binaries=binaries,
|
binaries=binaries,
|
||||||
datas=datas,
|
datas=datas,
|
||||||
hiddenimports=collect_submodules('celery.fixups') + [
|
hiddenimports=collect_submodules('celery.fixups') + _scipy_hidden + [
|
||||||
'uvicorn.logging',
|
'uvicorn.logging',
|
||||||
'uvicorn.loops',
|
'uvicorn.loops',
|
||||||
'uvicorn.loops.auto',
|
'uvicorn.loops.auto',
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
### [2026-08-08] FIX: Windows runtime — ModuleNotFoundError scipy.stats._ansari_swilk_statistics + ValueError librosa stub (PyInstaller bundle)
|
||||||
|
- **Tóm tắt thay đổi:** User chạy bản Windows exe gặp 2 lỗi runtime (hộp thoại error):
|
||||||
|
1. `ModuleNotFoundError: No module named 'scipy.stats._ansari_swilk_statistics'` — scipy >= 1.18 tách `scipy.stats` thành nhiều module con import LAZY bên trong hàm (vd `_ansari_swilk_statistics`) → hook scipy của PyInstaller không thấy → thiếu trong bundle. Fix: `engine.spec` thêm `collect_submodules('scipy')` vào hiddenimports (collect toàn bộ stats/signal/ndimage/... — không sót module nào).
|
||||||
|
2. `ValueError: Cannot load imports from non-existent stub '..._MEIxxxx\librosa\__init__.pyi'` — librosa 0.11 dùng `lazy_loader.attach_stub` → lúc RUNTIME cần file `.pyi` tồn tại trên disk, nhưng PyInstaller mặc định KHÔNG bundle `.pyi` (4 file: `__init__.pyi`, `core/`, `feature/`, `util/`). Fix: `datas += collect_data_files('librosa', includes=['**/*.pyi'])`.
|
||||||
|
- **Các file ảnh hưởng:** `engine.spec` (import collect_data_files + _scipy_hidden + librosa .pyi datas)
|
||||||
|
- **Ghi chú/Test (nếu có):** VERIFY THẬT bằng build PyInstaller trên Linux (cùng engine.spec, cần objdump/objcopy từ NDK llvm) → chạy binary frozen → `/health` OK, `/` 200, `/static/js/app.precompiled.js` 200, không còn 2 lỗi trên. pytest 86 passed. Lưu ý: máy user cần build lại bằng `build_windows.ps1` để có exe mới.
|
||||||
|
|
||||||
|
---
|
||||||
### [2026-08-08] FIX: Windows build crash — 'app\static does not exist' (PyInstaller datas relative) + FIX: ARM track + MIDI keyboard → VU meter đứng yên
|
### [2026-08-08] FIX: Windows build crash — 'app\static does not exist' (PyInstaller datas relative) + FIX: ARM track + MIDI keyboard → VU meter đứng yên
|
||||||
- **Tóm tắt thay đổi:** 2 bug trên bản Windows standalone:
|
- **Tóm tắt thay đổi:** 2 bug trên bản Windows standalone:
|
||||||
1. **Build crash 6 hộp thoại error**: `RuntimeError: Directory '...\_MEIxxxx\app\static' does not exist` khi chạy daw_engine.exe. Root cause: `app/main.py` dùng `os.path.dirname(__file__)` để mount /static — khi frozen `__file__` trỏ vào thư mục giải nén tạm `_MEI...` KHÔNG phải `sys._MEIPASS`; đồng thời `engine.spec` datas dùng path RELATIVE (resolve theo CWD lúc chạy `pyinstaller`, chạy từ nơi khác → bỏ qua âm thầm → static/templates/models thiếu trong bundle). Fix: `main.py` dùng `settings.APP_DIR` (freeze-aware, config.py đã có); `engine.spec` đổi toàn bộ datas + pathex sang ABSOLUTE từ `SPECPATH` + thêm `app/models` (project_schema.json — projects.py dùng, trước đây thiếu khi frozen).
|
1. **Build crash 6 hộp thoại error**: `RuntimeError: Directory '...\_MEIxxxx\app\static' does not exist` khi chạy daw_engine.exe. Root cause: `app/main.py` dùng `os.path.dirname(__file__)` để mount /static — khi frozen `__file__` trỏ vào thư mục giải nén tạm `_MEI...` KHÔNG phải `sys._MEIPASS`; đồng thời `engine.spec` datas dùng path RELATIVE (resolve theo CWD lúc chạy `pyinstaller`, chạy từ nơi khác → bỏ qua âm thầm → static/templates/models thiếu trong bundle). Fix: `main.py` dùng `settings.APP_DIR` (freeze-aware, config.py đã có); `engine.spec` đổi toàn bộ datas + pathex sang ABSOLUTE từ `SPECPATH` + thêm `app/models` (project_schema.json — projects.py dùng, trước đây thiếu khi frozen).
|
||||||
|
|||||||
Reference in New Issue
Block a user