I’m trying to deploy a ML model I’ve developed in Python as an Azure function.
For that, I’m following the tutorial here since I know close to nothing related with Azure functions.
After creating the local project, and upon following the instructions on step 1 of "Run the function locally":
To start the function locally, press F5 or the play icon. The Terminal
panel displays the Output from Core Tools.
When doing this, nothing happens.
According to the tutorial, I should see the URL endpoint of my HTTP-triggered function running locally as per below image from the tutorial:
Therefore, I’m stuck again!
Can anyone help?
EDIT:
I’m launching VsCode from Anaconda, through a virtual environment (novo).
This is the code of init.py:
import logging
import azure.functions as func
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
2
Answers
I followed the tutorial, and it worked for me:
Creating Python AZ Function and Debugin
Look like you are having a problem with something that changed location.
How did you start? did you launch VS Code with File>New Window? When you click the "+" besides "workspace" and create a new function, did you click "create new project" and selected a folder? It seems something got lost/corrupted during that but could also be the version of your VS code. I would suggest you make sure you have the latest VS Code, the latest version of the "Azure Functions" add-on:
Azure function Add-on for VS Code
Steps
Trust check
Required things to be installed for running the Python Azure Function in VS Code locally are:
When coming to the specific errors like
It seems to be dotnet is not included in the System Environment Variables Path. Download .NET Core 6 SDK + Runtime and Check the installed path is added to the Environment Variables:
In the Command Prompt, run
dotnet --version
Windows Search 🪟 Button > Search for Environment Variables > Open & Click 🖱️ on Environment Variables >
Below code copied from my VS Code Azure Functions Python project:
requirements.txt :
local.settings.json:
host.json:
function.json: