v1.7.6: secondo tentativo fix avvio Windows pythonnet
Preload esplicito di pythonnet.load("netfx") in main.py PRIMA di
importare webview: il lazy-import del 'clr' fallisce sotto PyInstaller
perche' Python.Runtime.dll viene bundlata ma il loader netfx non sa
risolverla.
Aggiunti:
- main.py: bootstrap pythonnet con PYTHONNET_RUNTIME=netfx + load()
- build_windows.py: --clean rebuild, --collect-data pythonnet/clr_loader
(per Python.Runtime.runtimeconfig.json e altri non-Python files),
hidden-import clr_loader.netfx
This commit is contained in:
1 parent
891562dc88
commit
2cc6c5e9c6
3 files changed
+35
-1
No files matched your search
@@ -106,6 +106,9 @@ def run_pyinstaller():
|
|||||||
"--windowed",
|
"--windowed",
|
||||||
"--onedir",
|
"--onedir",
|
||||||
"--noconfirm",
|
"--noconfirm",
|
||||||
|
# Forza rebuild pulita (senza, residui di build vecchi possono
|
||||||
|
# confondere il bundling di pythonnet/clr_loader).
|
||||||
|
"--clean",
|
||||||
]
|
]
|
||||||
if icon_path.exists():
|
if icon_path.exists():
|
||||||
cmd.extend(["--icon", str(icon_path)])
|
cmd.extend(["--icon", str(icon_path)])
|
||||||
@@ -118,6 +121,9 @@ def run_pyinstaller():
|
|||||||
"--hidden-import", "webview.platforms.winforms",
|
"--hidden-import", "webview.platforms.winforms",
|
||||||
"--hidden-import", "clr",
|
"--hidden-import", "clr",
|
||||||
"--hidden-import", "clr_loader",
|
"--hidden-import", "clr_loader",
|
||||||
|
"--hidden-import", "clr_loader.netfx",
|
||||||
|
"--hidden-import", "clr_loader.types",
|
||||||
|
"--hidden-import", "pythonnet",
|
||||||
"--hidden-import", "requests",
|
"--hidden-import", "requests",
|
||||||
# Collegamenti completi: webview, pythonnet, clr_loader (porta
|
# Collegamenti completi: webview, pythonnet, clr_loader (porta
|
||||||
# con se Python.Runtime.dll + nethost.dll + runtimeconfig.json
|
# con se Python.Runtime.dll + nethost.dll + runtimeconfig.json
|
||||||
@@ -127,6 +133,11 @@ def run_pyinstaller():
|
|||||||
"--collect-all", "pythonnet",
|
"--collect-all", "pythonnet",
|
||||||
"--collect-all", "clr_loader",
|
"--collect-all", "clr_loader",
|
||||||
"--collect-all", "mutagen",
|
"--collect-all", "mutagen",
|
||||||
|
# collect-data prende anche i file .json/.dll non-Python che
|
||||||
|
# collect-all potrebbe saltare (Python.Runtime.runtimeconfig.json
|
||||||
|
# in particolare).
|
||||||
|
"--collect-data", "pythonnet",
|
||||||
|
"--collect-data", "clr_loader",
|
||||||
"--copy-metadata", "pythonnet",
|
"--copy-metadata", "pythonnet",
|
||||||
"--copy-metadata", "clr_loader",
|
"--copy-metadata", "clr_loader",
|
||||||
# Binari bundled
|
# Binari bundled
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
VERSION = "v1.7.5"
|
VERSION = "v1.7.6"
|
||||||
|
|
||||||
|
|
||||||
APP_NAME = "MusicTools"
|
APP_NAME = "MusicTools"
|
||||||
|
|||||||
@@ -4,6 +4,29 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Windows: forza il caricamento del runtime pythonnet PRIMA di importare
|
||||||
|
# webview. Con PyInstaller il lazy-loader fallisce con
|
||||||
|
# "Failed to resolve Python.Runtime.Loader.Initialize" perche'
|
||||||
|
# Python.Runtime.dll viene bundlata ma il loader non sa risolverla
|
||||||
|
# senza l'inizializzazione esplicita. Fix conferma:
|
||||||
|
# https://github.com/pythonnet/pythonnet/issues/2178
|
||||||
|
if sys.platform == "win32":
|
||||||
|
try:
|
||||||
|
# Punta pythonnet ai propri file runtime dentro al bundle PyInstaller.
|
||||||
|
if getattr(sys, "frozen", False):
|
||||||
|
_bundle = Path(sys._MEIPASS) # type: ignore[attr-defined]
|
||||||
|
_rt = _bundle / "pythonnet" / "runtime"
|
||||||
|
if _rt.exists():
|
||||||
|
os.environ["PYTHONNET_RUNTIME"] = "netfx"
|
||||||
|
os.environ["PYTHONNET_PYDLL"] = sys.executable
|
||||||
|
from pythonnet import load as _pythonnet_load
|
||||||
|
_pythonnet_load("netfx")
|
||||||
|
import clr # noqa: F401 - inizializza il loader
|
||||||
|
except Exception as _e:
|
||||||
|
# Se il preload fallisce, lasciamo che webview tenti comunque:
|
||||||
|
# l'errore originale verra' mostrato con stack trace.
|
||||||
|
print(f"[bootstrap] preload pythonnet failed: {_e}")
|
||||||
|
|
||||||
import webview
|
import webview
|
||||||
|
|
||||||
from api.bridge import Api
|
from api.bridge import Api
|
||||||
|
|||||||
Reference in new issue
Block a user