You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSL环境VSCode调试Python Azure Function App提示找不到'func: host start'任务

解决WSL环境下VS Code调试Python Azure Function的"func: host start"任务缺失问题

1. 手动创建.vscode/tasks.json配置

由于Azure Functions扩展未自动生成任务配置,手动在项目的.vscode目录下创建tasks.json文件,添加以下内容:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "func: host start",
      "type": "shell",
      "command": "func host start",
      "args": [],
      "isBackground": true,
      "problemMatcher": "$func-python-watch",
      "dependsOn": "pip install (functions)"
    },
    {
      "label": "pip install (functions)",
      "type": "shell",
      "command": "/usr/bin/python3 -m pip install -r requirements.txt",
      "problemMatcher": []
    }
  ]
}
  • 若你的Python可执行文件路径非默认,将/usr/bin/python3替换为WSL中实际的Python绝对路径(比如/usr/bin/python3.10)。

2. 验证launch.json的任务关联

打开.vscode/launch.json,确认preLaunchTask字段值与tasks.json中的任务label完全一致:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Python Functions",
      "type": "python",
      "request": "attach",
      "port": 9091,
      "preLaunchTask": "func: host start",
      "justMyCode": true
    }
  ]
}

3. 确保func工具使用正确的Python环境

在local.settings.json中添加Python环境变量,指定WSL中的Python路径:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "PYTHONPATH": "/usr/bin/python3"
  }
}

替换/usr/bin/python3为你实际使用的Python可执行文件路径。

4. 手动调试备选方案

若自动启动任务仍异常,可分两步操作:

  • 打开WSL终端,进入Function项目目录,执行func host start --port 9091启动函数宿主
  • 在VS Code中选择"Attach to Python Functions"启动配置,直接附加到运行中的宿主进程

额外检查项

  • 确认Azurite服务处于运行状态(可通过VS Code状态栏查看)
  • 确保项目目录下的requirements.txt依赖已安装,终端执行pip install -r requirements.txt
  • 检查WSL中func工具的执行权限,确保func host start可正常运行

内容的提问来源于stack exchange,提问作者David Gard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 11:06:22