如何使用虚拟环境调试python函数应用程序

2024-04-24 13:19:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试做一件基本的事情:使用虚拟环境调试python函数应用程序。你知道吗

visualstudio代码文档没有指明如何做,我自己也无法理解:https://code.visualstudio.com/docs/python/debugging

我使用以下命令从终端运行应用程序:

.venv36\scripts\activate
func start

应用程序从我的虚拟环境运行,一切正常。你知道吗

为了进行调试,调试器使用启动.json地址:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Python Functions",
            "type": "python",
            "request": "attach",
            "port": 9091,
            "windows": {
                "pythonPath": ".venv36\\Scripts\\python.exe"
            },
            "preLaunchTask": "func: host start"
        }
    ]
}

阅读https://code.visualstudio.com/docs/python/environments,我将以下设置添加到设置.json地址:

{
   ...
    "python.pythonPath": ".venv36\\Scripts\\python.exe",
    "python.pipenvPath": ".venv36\\Scripts\\pip.exe",
    "python.venvPath": ".venv36",
    "python.terminal.activateEnvironment": true,

那个任务.json是:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "func",
            "command": "host start",
            "problemMatcher": "$func-watch",
            "isBackground": true,
            "options": {
                "cwd": "${workspaceFolder}/AlarmScoringFuncApp"
            }
        }
    ]
}

当我开始调试时,应用程序启动了,但不是在正确的环境中:它使用的是系统库,而不是为我的项目安装的系统库要求.txt. 你知道吗

我的应用程序尝试使用系统环境中未安装的库时崩溃。你知道吗


Tags: httpscomjson应用程序docs地址系统虚拟环境