I have faithfully followed this tutorial on how to create a python durable function and everything went well.
However able to start the project from the CLI, within the context of virtual env, I am unable to start vscode debugging.
Vscode python interpreter was set to the one inside .env, but consistently I get ModuleNotFoundError
, more specifically the module 'azure.durable_functions'
-surely installed- when starting debug.
requirements.txt
azure-functions
azure-functions-durable
.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Python Functions",
"type": "python",
"request": "attach",
"port": 9091,
"preLaunchTask": "func: host start",
}
]
}
.vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"label": "func: host start",
"command": "host start",
"problemMatcher": "$func-python-watch",
"isBackground": true
}
]
}
This issue was reproduced in two different Windows machines and an Ubuntu one.
Python version: 3.11 Vscode version: latest and 1.77.3
Upon reviewing the process, I realized I had skipped a step while creating the function project through vscode. More specifically:
In Visual Studio Code, press F1 (or Ctrl/Cmd+Shift+P) to open the command palette. In the command palette, search for and select Azure Functions: Create New Project....
However, when initializing the project from within VSCode it automatically generates the necessary debugging configuration files.
As I have created the function projects from the CLI I didn't find it necessary to "recreate" things from the IDE. Anyhow, this resolved the debugging issue.
Updated debugging files:
settings.json
{
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".env",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen"
}
task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"label": "func: host start",
"command": "host start",
"problemMatcher": "$func-python-watch",
"isBackground": true,
"dependsOn": "pip install (functions)"
},
{
"label": "pip install (functions)",
"type": "shell",
"osx": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"windows": {
"command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
},
"linux": {
"command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
},
"problemMatcher": []
}
]
}
launch.json and extensions.json remains the same. Thanks @ikhtesam for your insights.