I have been having a little bit of inconsistency issue with python settings in VS code while trying to run my azure functions locally. I am trying to avoid using the "venv" environment that VS code automatically sets for an azure function project and instead use a pre-created conda environment I made and have all the requirement installed in.Just to clarify, this is about local deployment and not azure portal.
myfunc__init__.py:
import json
import logging
import time
import azure.functions as func
import pandas as pd # Import Error happens here!
def main(req: func.HttpRequest) -> func.HttpResponse:
...
.vscode\Settings.json:
{
// Local Machine Conda VENV (Define CONDAPATH in Windows Environment)
"python.condaPath": "%CONDAPATH%",
"python.pythonPath": "%CONDAPATH%\\envs\\azure\\python.exe",
"azureFunctions.pythonVenv": "%CONDAPATH%\\envs\\azure",
// Created Local VENV by VS Code (pythonPath is difference for MAC vs Windows)
//"azureFunctions.pythonVenv": ".venv",
// Azure Function Stuff
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~2",
"azureFunctions.preDeployTask": "func: pack --build-native-deps",
"debug.internalConsoleOptions": "neverOpen",
}
Note: If I replace the %CONDAPATH%
with an actual absolute path to conda, the issue remains.
Just in case of need, launch.json
is configured as bellow:
{
"version": "0.2.0",
"configurations": [
{
"name": "Linux_PyFunc",
"type": "python",
"request": "attach",
"port": 9091,
"preLaunchTask": "func: host start"
}
]
}
When VS Code runs the functions, the deployment completes without issues and the local links are generated. Once I call the function via Postman
, the return is HTTP 500
status which is due to not being able to import pandas
with error module not found.
If I set "azureFunctions.pythonVenv": ".venv"
in settings.json
the functions gets deployed locally and once triggered/called, it returns HTTP 200
status and proper response.
So, this brings me to the question, if VS code supports conda environment for azure function deployment and if so, what am I missing here?