From f42c1a1839f42f190e984d76e37eebf5e333bc17 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 24 Nov 2025 12:18:15 +0000 Subject: [PATCH] include pythonnet runtime DLLs in build process to prevent missing dependencies --- build.py | 17 ++++++++++++++++- nice_uploader.spec | 23 +++++++++++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/build.py b/build.py index ad64f8e..79aee76 100644 --- a/build.py +++ b/build.py @@ -44,6 +44,21 @@ def build(build: bool = True, copy: bool = True, test: bool = False, dest: str | except Exception as e: print(f"Warning: couldn't locate dicognito package: {e}") + # Try to include pythonnet runtime DLLs to avoid missing + # Python.Runtime.dll at runtime (used by pythonnet / webview). + add_binary_args = [] + 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"): + # PyInstaller on Windows expects 'src;dest' + add_binary_args += ["--add-binary", f"{str(f)};pythonnet\\runtime"] + except Exception as e: + print(f"Warning: couldn't locate pythonnet runtime: {e}") + PyInstaller.__main__.run([ str(project_root / "nice.py"), "--onefile", @@ -55,7 +70,7 @@ def build(build: bool = True, copy: bool = True, test: bool = False, dest: str | str(project_root / "build" / "test"), "--specpath", str(project_root / "build" / "specs"), - ] + add_data_args + [ + ] + add_data_args + add_binary_args + [ # add some common hidden imports that PyInstaller sometimes misses "--hidden-import", "bs4", diff --git a/nice_uploader.spec b/nice_uploader.spec index b2a9751..4a82542 100644 --- a/nice_uploader.spec +++ b/nice_uploader.spec @@ -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={},