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 tend
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 10, 2025
1 parent a00a332 commit bdb9c34
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
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 bdb9c34

Please sign in to comment.