{Packaging} Prepend embedded Python folder to PYTHONPATH on Windows#30801
{Packaging} Prepend embedded Python folder to PYTHONPATH on Windows#30801
PYTHONPATH on Windows#30801Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
|
Thank you for your contribution orgads! We will review the pull request and get back to you soon. |
|
At a glance, I have no idea why it adds However, this won't fix the issue. |
Oops, you're right. Fixed and tested this time - both on bash and cmd. |
|
Updated the commit message and the PR description accordingly. |
|
I guess ps1 script should also be updated, but it is signed, so I can't edit it. You can add this in the first line: $env:PYTHONPATH="$PSScriptRoot\..;$env:PYTHONPATH" |
|
What's the output of this in your computer, and what's the version of the extra Python? I guess bumping it to 3.12.8 can also fix the crash. |
My local Python is 3.12.6. There shouldn't be any dependency between the bundled python and system python. You cannot expect users to follow which python version you bundle and upgrade their local python accordingly. Do you see anything wrong with the suggested fix? |
|
I just want to confirm that the root cause is the compatibility issue between 3.12.x and 3.12.8. I have concern about the changes in Here is a related issue: pypa/pip#13023. There is no easy way to let pip ignore |
| @IF EXIST "%~dp0\..\python.exe" ( | ||
| SET PYTHONPATH=%~dp0\..;%PYTHONPATH% | ||
| SET AZ_INSTALLER=ZIP | ||
| "%~dp0\..\python.exe" -IBm azure.cli %* |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Is this just an observation, or do you want me to change anything in my commit?
|
This PR fixes the pip crash issue when user installed another python, and pip loads the wrong module from user's installed python. See #30594 (comment) |
PYTHONPATH on Windows
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 <base>/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 Azure#25067, Azure#28004, Azure#29630, Azure#30517, Azure#30536, Azure#30594, Azure#30700, Azure#30792.
PYTHONPATH on WindowsPYTHONPATH on Windows
|
ping? |
|
I'm able to repro this by installing Python 3.12.6. I initially liked this solution because it might also fix the Windows pip compile package issue. However, after checking again, it doesn't resolve the problem. @jiasli to share more insight. |
Setting PYTHONPATH is done to avoid conflicts with other installations of Python on the same machine. When it is set incorrectly, python crash on startup (typically when loading incompatible ctypes). see #30594 (comment)
Update the scripts to prepend
CLI2in PYTHONPATH.Fix #29630, #30517, #30536, #30594, #30700, #30792.
PS: In
src/azure-cli/azandsrc/azure-cli/az.bat,srcis added inPYTHONPATH. It seems to be a mistake. But these scripts no longer seem to be used.This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.