include pythonnet runtime DLLs in build process to prevent missing dependencies

This commit is contained in:
Ross
2025-11-24 12:18:15 +00:00
parent 094d66b137
commit f42c1a1839
2 changed files with 37 additions and 3 deletions
+21 -2
View File
@@ -1,16 +1,35 @@
# -*- mode: python ; coding: utf-8 -*-
import os
import importlib.util
from pathlib import Path
here = Path(__file__).resolve().parent
project_root = here
# Prepare datas and binaries lists; include icon resources
datas = [(str(project_root / 'icon'), 'icon'), (str(project_root / 'icon' / 'icon1.png'), 'icon')]
binaries = []
# Try to include pythonnet runtime DLLs so Python.Runtime.dll is available
try:
spec_py = importlib.util.find_spec("pythonnet")
if spec_py and spec_py.submodule_search_locations:
pn_path = Path(spec_py.submodule_search_locations[0])
runtime_dir = pn_path / "runtime"
if runtime_dir.exists():
for f in runtime_dir.rglob("*.dll"):
# destination folder inside the frozen app
binaries.append((str(f), "pythonnet/runtime"))
except Exception:
# best-effort; if we can't locate pythonnet at build time, user can add it manually
pass
a = Analysis(
['nice.py'],
pathex=[str(project_root)],
binaries=[],
datas=[(str(project_root / 'icon'), 'icon'), (str(project_root / 'icon' / 'icon1.png'), 'icon')],
binaries=binaries,
datas=datas,
hiddenimports=['bs4', 'requests', 'nicegui', 'pynng'],
hookspath=[],
hooksconfig={},