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 .venvLibsite-packagesazure_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.
2
Answers
Mea culpa.
It turns out I had an old, lingering installation of Python 3.7 on my laptop from some time back. Once I uninstalled it, everything loaded as it should.
Thanks everyone who took a gander at my question.
When you are using virtual environment. you need to install
requirements.txt
file inside virtual environment.To activate virtual environment follow these commands
you will see virtual environment tag
(.venv)
in front as shown below.This worked for me.
requirements.txt
:OUTPUT
: