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
+16 -1
View File
@@ -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",