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
Suggested fix
- Expose
az as a console_scripts entry 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 import azure.cli, and emit a clear error otherwise. Silently running an arbitrary interpreter produces a confusing ModuleNotFoundError far 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 from PATH
Additional context
No response
Describe the bug
On Windows, when
azure-cliis installed from PyPI by a tool that places console shims in a sharedbindirectory (for exampleuv tool install azure-cli), the shippedaz.batsilently falls back to whateverpythonis first onPATHinstead of the interpreter of the environment azure-cli was installed into. That interpreter has noazurepackage, so every command fails.The cause is the interpreter probe in
src/azure-cli/az.bat:az.batis declared through setuptoolsscripts=rather than as aconsole_scriptsentry point, so installers copy the file verbatim. The probe assumes the copy still sits next to the environment'spython.exe. Any installer that relocates shims into a sharedbindirectory breaks that assumption, and theELSEbranch then executes an unrelated interpreter with no warning.The failure is shell-dependent on Windows, which makes it hard to diagnose.
PATHEXTcauses PowerShell andcmdto resolveazto the brokenaz.bat, while Git Bash ignoresPATHEXTand resolves the extensionlessazscript, 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
ELSEbranch (anaz.batunder one Python'sScriptsdirectory invoking a different Python fromPATH). It was closed for inactivity rather than fixed.PYTHONPATHon Windows #30801 states: "Insrc/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
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.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 versionandaz --version; the failure occurs before command dispatch, so it affects every command.Errors
Issue script & Debug output
--debugproduces no additional output: the failure happens in the.batlauncher, beforeazure.cliis imported and before any CLI argument parsing.Behaviour of each launcher present on one machine, using
az --versionto report the bound interpreter:wbin\az.cmdCLI2\python.exe(3.14.6)<uv tool venv>\Scripts\az.batpython.exe(3.14.4, adjacent, probe succeeds)~\.local\bin\az(extensionless, shebang)python.exe(3.14.4)~\.local\bin\az.bat(shim copied by uv)pythonfromPATHAll four share
~/.azureas config directory, so the login session is not involved; only the launcher differs.Expected behavior
azresolves 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
ModuleNotFoundErrorthat points nowhere near the cause.Environment Summary
uv tool install azure-cli(uv 0.12.13)az.bat: CPython 3.14 fromPATHAdditional context
No response