include pythonnet runtime DLLs in build process to prevent missing dependencies
This commit is contained in:
@@ -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",
|
||||
|
||||
+21
-2
@@ -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={},
|
||||
|
||||
Reference in New Issue
Block a user