Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

{Packaging} Prepend embedded Python folder to PYTHONPATH on Windows #30801

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %*
Copy link
Contributor

@bebound bebound Feb 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root cause of the crash is Python 3.12.8 loads 3.12.x's module(C:\\Users\\xxx\\AppData\\Local\\Programs\\Python\\Python312\\Lib) when run pip.(#30594 (comment))

We have -I option when run az, but we don't have it in pip.

cmd = [sys.executable, '-m', 'pip'] + pip_exec_args + ['--disable-pip-version-check', '--no-cache-dir']

Even though we can add -I in Line 49, it may not take effect, see pypa/pip#13023. Prepend ../ to PYTHONPATH is an intuitive workaround. (Setting PYTHONHOME also works)

) ELSE (
Expand Down