{Packaging} `az.bat` silently runs an unrelated Python when the shim is copied outside the environment's Scripts directory (e.g. `uv tool install azure-cli`)
I maintainer di solito rispondono entro 1 giorno
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Describe the bug
On Windows, when azure-cli is installed from PyPI by a tool that places console shims in a shared bin directory (for example uv tool install azure-cli), the shipped az.bat silently falls back to whatever python is first on PATH instead of the interpreter of the environment azure-cli was installed into. That interpreter has no azure package, so every command fails.
The cause is the interpreter probe in src/azure-cli/az.bat:
IF EXIST "%~dp0\python.exe" (
"%~dp0\python.exe" -m azure.cli %*
) ELSE (
python -m azure.cli %*
)
az.bat is declared through setuptools scripts= rather than as a console_scripts entry point, so installers copy the file verbatim. The probe assumes the copy still sits next to the environment's python.exe. Any installer that relocates shims into a shared bin directory breaks that assumption, and the ELSE branch then executes an unrelated interpreter with no warning.
The failure is shell-dependent on Windows, which makes it hard to diagnose. PATHEXT causes PowerShell and cmd to resolve az to the broken az.bat, while Git Bash ignores PATHEXT and resolves the extensionless az script, whose shebang correctly pins the environment's interpreter. The same machine and the same installation therefore succeed in one shell and fail in another.
Related issues
- #21737 reports the identical error from the same
ELSEbranch (anaz.batunder one Python'sScriptsdirectory invoking a different Python fromPATH). It was closed for inactivity rather than fixed. - #30801 states: "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." These scripts are the entry point for every PyPI installation on Windows, so that assumption does not hold for pip/uv installs.
Suggested fix
- Expose
azas aconsole_scriptsentry point. pip and uv both generate a Windows launcher that embeds the absolute path to the environment's interpreter, which removes the probe and makes shim relocation safe. This is the durable fix. - Failing that, drop the
ELSE python -m azure.cli %*fallback, or gate it behind a check that the interpreter can actually importazure.cli, and emit a clear error otherwise. Silently running an arbitrary interpreter produces a confusingModuleNotFoundErrorfar from its cause.
Related command
Any command. Reproduced with az version and az --version; the failure occurs before command dispatch, so it affects every command.
Errors
C:\Users\<user>\AppData\Local\Programs\Python\Python314\python.exe: Error while finding module specification for 'azure.cli' (ModuleNotFoundError: No module named 'azure')
Issue script & Debug output
> uv tool install azure-cli
> az version
C:\Users\<user>\AppData\Local\Programs\Python\Python314\python.exe: Error while finding module specification for 'azure.cli' (ModuleNotFoundError: No module named 'azure')
--debug produces no additional output: the failure happens in the .bat launcher, before azure.cli is imported and before any CLI argument parsing.
Behaviour of each launcher present on one machine, using az --version to report the bound interpreter:
| Launcher | Interpreter used | Result |
|---|---|---|
MSI wbin\az.cmd |
bundled CLI2\python.exe (3.14.6) |
works |
<uv tool venv>\Scripts\az.bat |
tool venv python.exe (3.14.4, adjacent, probe succeeds) |
works |
~\.local\bin\az (extensionless, shebang) |
tool venv python.exe (3.14.4) |
works |
~\.local\bin\az.bat (shim copied by uv) |
bare python from PATH |
fails |
All four share ~/.azure as config directory, so the login session is not involved; only the launcher differs.
Expected behavior
az resolves the interpreter of the environment it was installed into, regardless of where the launcher is placed.
If that interpreter cannot be located, the command should fail with an explicit message naming the problem, rather than silently executing an unrelated Python and surfacing a ModuleNotFoundError that points nowhere near the cause.
Environment Summary
- OS: Windows 11 Pro 26200
- Install method:
uv tool install azure-cli(uv 0.12.13) - azure-cli: 2.90.0
- Environment interpreter: CPython 3.14.4
- Interpreter wrongly selected by
az.bat: CPython 3.14 fromPATH
Additional context
No response
- Lingua principale
- Python
- Stelle
- 4.7k
- Fork
- 3.5k
- Merge medio
- 4g 14h
- PR unite (30g)
- 92
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Azure/azure-cli
-
customer-reported MySQL needs-triage Service Attention
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
Azure/azure-cli#34393 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
customer-reported Service Attention
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
Azure/azure-cli#34267 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Add support for cli completion in git bash for windowsForse già presa @a0x1ab l’ha presa 23 giorni fa. Apertacustomer-reported Service Attention
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Azure/azure-cli#34150 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
act-observability-squad Auto-Assign ContainerApp Output Service Attention
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Azure/azure-cli#33149 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
act-codegen-extensibility-squad Auto-Assign Documentation MySQL Possible-Solution Service Attention Similar-Issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
Azure/azure-cli#33009 · 5 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Azure/azure-cli
Issue simili
-
Unknown stop ID in slow zone data crashes post formatting and skips the rest of that day's postsApertabackend bug tm-new-volunteer
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
transitmatters/mbta-slow-zone-bot#81 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
spacetelescope/rdmt-spire#49 ·
I maintainer di solito rispondono entro 1 giorno
-
AI bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
AUTO-MAS-Project/AUTO-MAS#1960 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
btclib-org/btclib-wallet#872 ·
I maintainer di solito rispondono entro 1 giorno