Skip to content

Commit

Permalink
{Packaging} Fix crash when another Python is installed on the system
Browse files Browse the repository at this point in the history
The scripts are installed in <base>/Scripts, but PYTHONPATH was set to
<scripts>/src, although this directory doesn't even exist. I guess the
deployment used to be in src, but this is no longer the case.

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).

Fixes Azure#28004, Azure#29630, Azure#30517, Azure#30536, Azure#30594, Azure#30700, Azure#30792.
  • Loading branch information
orgads committed Feb 12, 2025
1 parent e1a34cc commit 3b562f9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion build_scripts/windows/scripts/az
Original file line number Diff line number Diff line change
@@ -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 "$@"
1 change: 1 addition & 0 deletions build_scripts/windows/scripts/az_msi.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
::

@IF EXIST "%~dp0\..\python.exe" (
SET PYTHONPATH=%~dp0\..;%PYTHONPATH%
SET AZ_INSTALLER=MSI
"%~dp0\..\python.exe" -IBm azure.cli %*
) ELSE (
Expand Down
1 change: 1 addition & 0 deletions build_scripts/windows/scripts/az_zip.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
::

@IF EXIST "%~dp0\..\python.exe" (
SET PYTHONPATH=%~dp0\..;%PYTHONPATH%
SET AZ_INSTALLER=ZIP
"%~dp0\..\python.exe" -IBm azure.cli %*
) ELSE (
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/az
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
import os

dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'src')
dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

if os.environ.get('PYTHONPATH') is None:
os.environ['PYTHONPATH'] = dir
Expand Down
6 changes: 3 additions & 3 deletions src/azure-cli/az.bat
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@echo off
setlocal

SET PYTHONPATH=%~dp0\src;%PYTHONPATH%
SET PYTHONPATH=%~dp0\..;%PYTHONPATH%
SET AZ_INSTALLER=PIP

IF EXIST "%~dp0\python.exe" (
"%~dp0\python.exe" -m azure.cli %*
IF EXIST "%~dp0\..\python.exe" (
"%~dp0\..\python.exe" -m azure.cli %*
) ELSE (
python -m azure.cli %*
)

0 comments on commit 3b562f9

Please sign in to comment.