Skip to content

Commit f0d0d7c

Browse files
committed
fix(build): collect numpy/pandas submodules & dynamic libs to fix numpy 2.x import on frozen builds
1 parent b9daeb9 commit f0d0d7c

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: |
4343
python -m pip install --upgrade pip
4444
pip install -r requirements.txt
45-
pip install pyinstaller==6.11.1
45+
pip install "pyinstaller>=6.14"
4646
4747
- name: Build with PyInstaller
4848
run: pyinstaller --noconfirm deltalab.spec

deltalab.spec

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,34 @@ Outputs:
1212

1313
import sys
1414
from pathlib import Path
15-
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
15+
from PyInstaller.utils.hooks import (
16+
collect_data_files,
17+
collect_dynamic_libs,
18+
collect_submodules,
19+
)
1620

1721
ROOT = Path(SPECPATH).resolve()
1822

1923
datas = []
2024
datas += [(str(ROOT / "assets"), "assets")]
2125
datas += collect_data_files("matplotlib")
26+
# numpy 2.x 把 numpy.core 改名为 numpy._core, 有些子模块 (如 _exceptions) 需要
27+
# 显式通过 data 文件形式带上元数据, 避免运行时 "No module named numpy._core._exceptions".
28+
datas += collect_data_files("numpy")
29+
30+
binaries = []
31+
# 把 numpy/scipy/pandas/pyarrow 的 C 扩展 (.pyd/.so) 全部收齐, 防止漏掉某个
32+
# _multiarray_umath / _exceptions 之类的动态库.
33+
for _pkg in ("numpy", "scipy", "pandas", "pyarrow"):
34+
binaries += collect_dynamic_libs(_pkg)
2235

2336
hiddenimports = []
37+
# numpy 2.x 的私有子模块在模块图里常被遗漏, 强制全收.
38+
hiddenimports += collect_submodules("numpy")
2439
# scipy 有大量子模块通过字符串间接导入, 一次性收齐避免运行时 ImportError.
2540
hiddenimports += collect_submodules("scipy")
2641
# pandas / pyarrow 的 IO 后端
42+
hiddenimports += collect_submodules("pandas")
2743
hiddenimports += ["pyarrow", "pyarrow.parquet", "pyarrow.vendored.version"]
2844
# 项目内部的定价子模块 (通过字符串/懒加载使用)
2945
hiddenimports += collect_submodules("pricing")
@@ -40,7 +56,7 @@ block_cipher = None
4056
a = Analysis(
4157
["gui_app.py"],
4258
pathex=[str(ROOT)],
43-
binaries=[],
59+
binaries=binaries,
4460
datas=datas,
4561
hiddenimports=hiddenimports,
4662
hookspath=[],

0 commit comments

Comments
 (0)