From 42eece89a2e6902fff6d25ad2792b1851271408c Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 10 Feb 2025 22:47:36 +0200 Subject: [PATCH] {Packaging} Fix crash when another Python is installed on the system Setting PYTHONPATH is done to avoid conflicts with other installations of Python on the same machine. When it is set incorrectly Python tends to crash on startup (typically when loading incompatible ctypes). There were old scripts in /Scripts, which set PYTHONPATH so that Python prefers the bundled libs over the system ones. The problem with these scripts is that they set the wrong path. But these scripts no longer seem to be used. They were replaced by new ones in wbin. The problem with those is that PYTHONPATH was not set at all in them. Update the scripts to set PYTHONPATH correctly, both for bash and cmd. Fixes #25067, #28004, #29630, #30517, #30536, #30594, #30700, #30792. --- build_scripts/windows/scripts/az | 4 +++- build_scripts/windows/scripts/az_msi.cmd | 1 + build_scripts/windows/scripts/az_zip.cmd | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/build_scripts/windows/scripts/az b/build_scripts/windows/scripts/az index 6600548847e..d87c2401e90 100644 --- a/build_scripts/windows/scripts/az +++ b/build_scripts/windows/scripts/az @@ -1,3 +1,5 @@ #!/usr/bin/env bash -AZ_INSTALLER=MSI "$(dirname "${BASH_SOURCE[0]}")/../python.exe" -IBm azure.cli "$@" +SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}") +export PYTHONPATH="$(dirname "$SCRIPT_DIR")" +AZ_INSTALLER=MSI "$SCRIPT_DIR/../python.exe" -IBm azure.cli "$@" diff --git a/build_scripts/windows/scripts/az_msi.cmd b/build_scripts/windows/scripts/az_msi.cmd index 9e9708908c6..feb1549be65 100644 --- a/build_scripts/windows/scripts/az_msi.cmd +++ b/build_scripts/windows/scripts/az_msi.cmd @@ -4,6 +4,7 @@ :: @IF EXIST "%~dp0\..\python.exe" ( + SET PYTHONPATH=%~dp0\..;%PYTHONPATH% SET AZ_INSTALLER=MSI "%~dp0\..\python.exe" -IBm azure.cli %* ) ELSE ( diff --git a/build_scripts/windows/scripts/az_zip.cmd b/build_scripts/windows/scripts/az_zip.cmd index 07e4acb73ff..bdfec6953c2 100644 --- a/build_scripts/windows/scripts/az_zip.cmd +++ b/build_scripts/windows/scripts/az_zip.cmd @@ -4,6 +4,7 @@ :: @IF EXIST "%~dp0\..\python.exe" ( + SET PYTHONPATH=%~dp0\..;%PYTHONPATH% SET AZ_INSTALLER=ZIP "%~dp0\..\python.exe" -IBm azure.cli %* ) ELSE (