azure-sdk-for-python: Cannot import name 'AccessTokenInfo' from 'azure.core.credentials'

  • Package Name: az-ai-ml
  • Package Version: 1.19.0
  • Operating System: Linux
  • Python Version: 3.11

Describe the bug

[!NOTE] Apologies if this issue should have been created in a different repository. Please let me know if I should create this ticket elsewhere.

In this PR, the minimum version of azure-core was updated to include the new SupportTokenInfo protocol and AccessTokenInfo class. However, when attempting to install the Azure ML extension using:

az extension add --name ml

the following error occurs:

cannot import name 'AccessTokenInfo' from 'azure.core.credentials'

As this issue is currently disrupting our CI pipelines, we would be grateful for any guidance you can provide to help us address it promptly.

Possible Cause

This issue seems to arise because the Azure ML extension installs azure_identity-1.18.0, which relies on AccessTokenInfo from azure.core.credentials. However, azure-cli version 2.64.0 still uses an older version of azure-core (1.28.0), and hence the error above is thrown.

For reference, here’s the azure-cli requirements file.

To Reproduce Steps to reproduce the behavior:

  1. Install az cli
  2. Run az extension add --name ml

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 23 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks for the pointer to azure-identity @miladh – this works for me as a workaround on CI:

$ az extension add --upgrade --name ml -y
$ sudo /opt/az/bin/python3 -m pip install azure-identity==1.17.1

(use at your own risk)

@toby-coleman As a temporary solution, you can add the following to your requirements.txt for a quick CI pipelines fix:

azure-identity==1.17.1

Appears that there is some intermingling of dependencies.

Looking at where CLI extension dependencies are installed for me, (~/.azure/cliextensions/ml), I do see that there are compatible versions of azure-core and azure-identity installed. However, the versions of these packages installed in the azure-cli Python virtual environment (e.g. /opt/az/lib/python3.11/site-packages/) seem to take precedence at runtime causing incompatibilities.

I mentioned this in the linked azure-cli issue, but I think something may need updating in the dependency resolution logic when installing an extension. Ideally, azure-cli extension Python requirements should remain compatible with the base azure-cli requirements when the extension is installed (i.e. azure-identity 1.17.1 should automatically have been installed with the ML extension).

I believe the workaround, as mentioned above, is to install an older version of azure-identity in whatever virtual environment azure-cli is using.

Example workarounds:

Linux:

sudo /opt/az/bin/python3 -m pip install azure-identity==1.17.1

Windows (in elevated/administrator terminal):

C:\"Program Files (x86)"\"Microsoft SDKs"\Azure\CLI2\python.exe -m pip install azure-identity==1.17.1

Not sure about Mac, but probably just need to run the python executable somewhere in /opt/homebrew/Cellar/azure-cli/<version>/libexec/ ?

I think you can glean the location of the environment your azure-cli is using based on the error message:

cannot import name 'AccessTokenInfo' from 'azure.core.credentials' (/opt/az/lib/python3.11/site-packages/azure/core/credentials.py) -> Need to use python executable somewhere in /opt/az