简体   繁体   English

使用 vscode 和 conda 在本地调试 azure function

[英]debugging azure function locally with vscode and conda

there has been multiple articles online on how to run somewhat similar scenario.网上有多篇关于如何运行类似场景的文章。

I have tried following and nothing works completely.我试过以下但没有任何效果。

  1. Used conda at machine level在机器级别使用 conda
  2. used conda inside VScode在 VScode 中使用 conda
  3. used venv (not conda).使用 venv(不是 conda)。

issue is how launch.json calls "host start".问题是 launch.json 如何调用“主机启动”。 this command changes into whatever is the value of "azureFunctions.pythonVenv" and then append " /Scripts/activate ".此命令更改为“azureFunctions.pythonVenv”的值,然后更改为 append“ /Scripts/activate ”。

now the issue is.现在的问题是。

  1. if i am using conda inside vscode, which creates ".conda" folder inside my workspace.如果我在 vscode 中使用 conda,它会在我的工作区中创建“.conda”文件夹。 this particular conda is missing "activate" file so command fails.这个特定的 conda 缺少“激活”文件,因此命令失败。

  2. if i use conda at machine level, it works, but it starts conda with environment as "base".如果我在机器级别使用 conda,它可以工作,但它以环境作为“基础”启动 conda。 there is no way i can change the environment inside "task.json", which type is "func"我无法更改“task.json”中的环境,类型为“func”

  3. i can change type of task from "func" to "shell", and then i can activate required env in conda, and azure function runs too.我可以将任务类型从“func”更改为“shell”,然后我可以在 conda 中激活所需的环境,并且 azure function 也运行。 but it doesn't go into debug mode.但它不会 go 进入调试模式。 it just gives connection error for:9091.它只是给出连接错误:9091。

After burning multiple days on this issue.在这个问题上燃烧了多天之后。 I can say that VSCODE + conda (not base) + AzureFunction + Debug doesnt work.我可以说 VSCODE + conda(不是基础)+ AzureFunction + Debug 不起作用。

this is a pain.这是一个痛苦。 once you have multiple programs on your local machine, you lost any benefit conda provides.一旦你的本地机器上有多个程序,你就失去了 conda 提供的任何好处。

Currently i am using option 2, as it atleast let me debug, which is a big deal for me.目前我正在使用选项 2,因为它至少让我调试,这对我来说很重要。

and again, everything works fine, if I just want to run AzureFunction, multiple ways to do that.再一次,一切正常,如果我只想运行 AzureFunction,有多种方法可以做到这一点。 But issue comes when i have to use conda (particular environment).但是当我必须使用 conda(特定环境)时,问题就来了。

config that worked, with using base conda.使用基本 conda 的有效配置。

tasks.json任务.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "pipInstall",
            "type": "shell",
            "windows": {
                "command": [
                    "conda.bat activate && pip install -r requirements.txt"
                ]
            },
            "problemMatcher": []
        },
        {
            "type": "func",
            "label": "func: host start",
            "command": "host start",
            "problemMatcher": "$func-python-watch",
            "isBackground": true,
            "dependsOn": ["pipInstall"]
        }
    ]
  }

settings.json (both settings may be a overkill, but its ok. settings.json(这两个设置可能有点矫枉过正,但没关系。

"python.defaultInterpreterPath": "C:XXXXXXXXX\\Miniconda3\\python.exe",
"azureFunctions.pythonVenv": "C:XXXXXXXXXXX\\Miniconda3",

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure -- 在本地调试配置了系统标识的 Powershell function - Azure -- debug locally a Powershell function that has System Identity configured 当我在本地运行 azure function(将数据上传到 cosmos)时,它会替换现有的 cosmos 数据吗? - When I run an azure function locally (which uploads a data to cosmos), does it replace the existing cosmos data? Azure function 在 visual Studio 本地运行时可以访问 Key Vault 但在门户上运行时不能 - Azure function can access Key Vault when run locally in visual Studio but not when run on the portal 在本地运行多个 Azure 函数 - Running multiple Azure Functions locally ILogger 在本地记录应用洞察,但不在 azure - ILogger logs to app insights locally but not on azure 使用远程 Docker 在本地 VSCode 中调试 AWS Lambda - Debug AWS Lambda in VSCode locally using remote Docker 在本地运行 golang lambda 函数 - Run golang lambda function locally 在本地运行 CDK API - Lambda function 在本地不起作用 - Running CDK API Locally - Lambda function doesn't work locally 如何使用 VSCode 修复 Azure web 应用程序部署错误? - How fix Azure web app deploy error with VSCode? 使用 SAM cli 和 AWS CDK 在本地调试时,AWS lambda 模块未找到错误? - AWS lambda module not found error when debugging locally using SAM cli and AWS CDK?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM