[Python] ModuleNotFoundError: No module named 'azure.identity'

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am making a foray into writing a webhook listener in Visual Studio Code using Python. I will admit I am a tyro, so do bear with me. The initial example in VSC for a webhook listener is straightforward. I run it locally in my terminal window using func host start, I then test it using Postman in VSC and get the expected response and a 200 status.

    But I want to do more than simply give a response/200, I want to grab the incoming JSON data, store it in Azure Data Lake, and then give a response. To do this, I have to add some libraries. The imports in my function_app.py file have gone from

    import logging

    import azure.functions as func


    to this

    import logging
    import datetime
    import os
    import json

    import azure.functions as func
    from azure.identity import DefaultAzureCredential
    from azure.keyvault.secrets import SecretClient
    from azure.storage.filedatalake import DataLakeServiceClient


    I updated my requirements.txt file so that it went from

    # DO NOT include azure-functions-worker in this file
    # The Python Worker is managed by Azure Functions platform
    # Manually managing azure-functions-worker may cause unexpected issues

    azure-functions


    to this

    # DO NOT include azure-functions-worker in this file
    # The Python Worker is managed by Azure Functions platform
    # Manually managing azure-functions-worker may cause unexpected issues

    azure-functions
    azure-storage-file-datalake
    azure-identity
    azure-keyvault
    requests


    My local.settings.json now includes entries for KEY_VAULT_URL, STORAGE_ACCOUNT_NAME, etc.

    Thinking all is set, I kick off the code in the terminal window using func host start and now get an error that boils down to ModuleNotFoundError: No module named 'azure.identity'.

    Somewhere it seems I've not told VSC where azure.identity exists. It is in .venv\Lib\site-packages\azure_identity-1.16.0.dist-info.

    I know I'm probably missing something very obvious to others, but I would be grateful for any suggestions.

    I have tried researching, using ChatGPT, GitHub Copilot, etc. but nothing seems to make a difference.

    I have performed pip installs of individual packages, I've done a pip install -r requirements.txt to ensure everything was available. I'm honestly at a loss.

    Continue reading...

Compartilhe esta Página