azure-sdk-for-python: Importing MLClient in online endpoint gives error "cannot import name TokenCredential from azure.core.credentials"

  • Package Name: azure-ai-ml
  • Package Version: 1.2.0
  • Operating System: mcr.microsoft.com/azureml/openmpi3.1.2-ubuntu18.04:latest
  • Python Version: 3.8

Describe the bug When trying to use ml client in a deployed online endpoint, from azure.ai.ml import MLClient causes cannot import name TokenCredential from azure.core.credentials

To Reproduce Steps to reproduce the behavior:

  1. create an online deployment
  2. create an online endpoint where you import mlclient

Expected behavior No import error, and a working mlclient

Additional context Perhaps you need another dependency(importing MLClient shouldn’t cause an import error except for “could not import MLCient” if the azure-ai-ml was not installed). Here are the ones i give the environment:

name: model-env
channels:
  - conda-forge
dependencies:
  - python=3.8
  - numpy=1.21.2
  - pip=22.3.1
  - scipy=1.7.1
  - pandas>=1.1,<1.2
  - pip:
    - inference-schema[numpy-support]==1.3.0
    - applicationinsights==0.11.10
    - sentence-transformers ==2.2.2
    - pytorch-lightning == 1.7.6
    - azure-ai-ml
    - azure-identity 
    - azureml-defaults==1.38.0

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

The DefaultAzureCredential assumes the AZURE_CLIENT_ID, AZURE_TENANT_ID, and AZURE_CLIENT_SECRET environment variables are set.

More details on configuring your environment to use the DefaultAzureCredential can be found in the class’s reference documentation: https://aka.ms/azsdk/python/identity/defaultazurecredential

Thanks, the workaround did work. Any idea when the fixes will get released @harneetvirk?

Thanks for responding @swathipil What you were saying were my thoughts exactly.

That is the entire list of dependencies.