From 47a62b1aed4c278c8384d6915b413d098116043d Mon Sep 17 00:00:00 2001 From: "alexei.dolgolyov" Date: Sun, 22 Mar 2026 03:14:12 +0300 Subject: [PATCH] fix: add app/src to embedded Python ._pth for module discovery Windows embedded Python ignores PYTHONPATH when a ._pth file exists. Add ../app/src to the ._pth so wled_controller is importable. Fixes ModuleNotFoundError on portable builds. --- build-dist-windows.sh | 7 ++++++- build-dist.ps1 | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/build-dist-windows.sh b/build-dist-windows.sh index 29af016..9ac86a5 100644 --- a/build-dist-windows.sh +++ b/build-dist-windows.sh @@ -73,11 +73,16 @@ if [ -z "$PTH_FILE" ]; then exit 1 fi -# Uncomment 'import site' and add Lib\site-packages +# Uncomment 'import site', add Lib\site-packages and app source path sed -i 's/^#\s*import site/import site/' "$PTH_FILE" if ! grep -q 'Lib\\site-packages' "$PTH_FILE"; then echo 'Lib\site-packages' >> "$PTH_FILE" fi +# Embedded Python ._pth overrides PYTHONPATH, so we must add the app +# source directory here for wled_controller to be importable +if ! grep -q '\.\./app/src' "$PTH_FILE"; then + echo '../app/src' >> "$PTH_FILE" +fi echo " Patched $(basename "$PTH_FILE")" # ── Download pip and install into embedded Python ──────────── diff --git a/build-dist.ps1 b/build-dist.ps1 index 65c40d6..883f95e 100644 --- a/build-dist.ps1 +++ b/build-dist.ps1 @@ -106,6 +106,11 @@ $pthContent = $pthContent -replace '#\s*import site', 'import site' if ($pthContent -notmatch 'Lib\\site-packages') { $pthContent = $pthContent.TrimEnd() + "`nLib\site-packages`n" } +# Embedded Python ._pth overrides PYTHONPATH, so add the app source path +# directly for wled_controller to be importable +if ($pthContent -notmatch '\.\.[/\\]app[/\\]src') { + $pthContent = $pthContent.TrimEnd() + "`n..\app\src`n" +} Set-Content -Path $pthFile.FullName -Value $pthContent -NoNewline Write-Host " Patched $($pthFile.Name)"