devcontainers/features

Azure-cli feature is broken for Python 3.12 as the distutils module is removed

PeterBosch2 opened this issue · 4 comments

How to reproduce?

Setup in a fresh VSCode environment a new DevContainer setup ... e.g., using the wizzard. Select Python on Debian Bookworm, add azure-cli feature. This results in the following devcontainer setup:

{
	"name": "Python 3",
	"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm",
	"features": {
		"ghcr.io/devcontainers/features/azure-cli:1": {}
	}
}

Re-opening VSCode in the container works fine, installation of the feature succeeds. However, the azure-cli does not work at the command line due to the missing distutils package, which is removed in Python 3.12:

vscode ➜ /workspaces/test $ az
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/local/pipx/venvs/azure-cli/lib/python3.12/site-packages/azure/cli/__main__.py", line 39, in <module>
    az_cli = get_default_cli()
             ^^^^^^^^^^^^^^^^^
  File "/usr/local/pipx/venvs/azure-cli/lib/python3.12/site-packages/azure/cli/core/__init__.py", line 917, in get_default_cli
    from azure.cli.core.azlogging import AzCliLogging
  File "/usr/local/pipx/venvs/azure-cli/lib/python3.12/site-packages/azure/cli/core/azlogging.py", line 30, in <module>
    from azure.cli.core.commands.events import EVENT_INVOKER_PRE_CMD_TBL_TRUNCATE
  File "/usr/local/pipx/venvs/azure-cli/lib/python3.12/site-packages/azure/cli/core/commands/__init__.py", line 25, in <module>
    from azure.cli.core.extension import get_extension
  File "/usr/local/pipx/venvs/azure-cli/lib/python3.12/site-packages/azure/cli/core/extension/__init__.py", line 11, in <module>
    from distutils.sysconfig import get_python_lib  # pylint: disable=deprecated-module
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'distutils'

Hi 👋

Thanks for reporting this issue, I was able to reproduce as well. Ideally, the Azure CLI team should fix it when one installs az with Python. @PeterBosch2 Can you open an issue, if one doesn't exist already?

However, we can still fix it on our end if we avoid using pip to install az -

  1. Check if az is available in bookworm apt feeds (looks like yes), if yes, then updating https://github.com/devcontainers/features/blob/main/src/azure-cli/install.sh#L21 should fix this issue for amd64

@gauravsaini04 / @prathameshzarkar9 Can you use my suggestion and help fix the issue?

@samruddhikhandale

@PeterBosch2 Can you open an issue, if one doesn't exist already?

I guess it is known: Azure/azure-cli#27673

There is a statement over there:

We don't guarantee Azure CLI works on all Python versions, such as the latest Python 3.12 or the deprecated Python 3.6. Installing Azure CLI with pip (Azure/azure-cli#20476) is only a supplemental feature we provide for unsupported platforms, but without any warranty.

Have added the possible fix in pr #909

PR was merged