在 VSCode 的 launch.json 配置里,programmodulecode 三个字段是互斥的,只能选一个。

用到 "program": "xxx.py" 的方式,配置里如果又用到 "module": "agents.llama_guard"


✅ 正确配置(用 module

比如跑 llama_guard.py,并且它依赖 from agents import ... / from core import ...,最合适的是 module 方式,而不是 program

.vscode/launch.json 配置改成这样:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Run llama_guard.py",
      "type": "python",
      "request": "launch",
      "module": "agents.llama_guard",
      "justMyCode": true,
      "env": {
        "PYTHONPATH": "${workspaceFolder}/src;${workspaceFolder}"
      }
    }
  ]
}

📌 补充说明

  • "module": "agents.llama_guard"
    等价于命令行:

    $env:PYTHONPATH="src;." ; python -m agents.llama_guard
    
  • 不要同时写 "program",否则就会报看到的这个错。

  • PYTHONPATH 环境变量保证能同时找到 src/agentscore


👉 如果确实想用 "program" 模式(直接指定脚本路径),可以这样写,但要注意 import 可能会报错:

{
  "name": "Run llama_guard (program mode)",
  "type": "python",
  "request": "launch",
  "program": "${workspaceFolder}/src/agents/llama_guard.py",
  "justMyCode": true,
  "env": {
    "PYTHONPATH": "${workspaceFolder}/src;${workspaceFolder}"
  }
}

更多推荐