首页 > 解决方案 > 如何配置 vscode 的 python 调试器以使用项目的终端而不是全局?

问题描述

将 python 调试器与 vscode 一起使用时,我希望它使用我在项目中选择的终端settings.json,而不是全局定义的终端。

具体来说,我将 WSL 的终端定义为 vscode 使用的默认终端,并将我的 python 项目配置为使用带有 anaconda 的 windows cmd。当我尝试使用集成终端调试 python 项目时,它尝试使用 WSL 启动文件,最终失败。我希望调试器使用 cmd。

我已经尝试launch.json在我的项目中调整,但似乎无法在此文件中选择任意终端。

我的launch.json文件如下所示:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

产生这些结果:

C:/Users/Owner/Anaconda3/Scripts/activate
C:\Users\Owner\Anaconda3\python.exe c:\Users\Owner\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 50893 e:\Software\project\.vscode\launch.json
conda activate base
owner@computer:/mnt/e/Software/project$ C:/Users/Owner/Anaconda3/Scripts/activate
-bash: C:/Users/Owner/Anaconda3/Scripts/activate: No such file or directory
owner@computer:/mnt/e/Software/project$ C:\Users\Owner\Anaconda3\python.exe c:\Users\Owner\.vscode\extensions\ms-python.python-2019.11.50794\pythonFiles\ptvsd_launcher.py --default --client --host localhost --port 50893 e:\Software\project\.vscode\launch.json
C:UsersOwnerAnaconda3python.exe: command not found
owner@computer:/mnt/e/Software/project$ conda activate base
conda: command not found
owner@computer:/mnt/e/Software/project$

如果我将launch.json文件更改为 use "console": "internalConsole",这允许软件运行,但我无法调试任何东西,断点不起作用等。

标签: pythonwindowsvisual-studio-codevscode-settingsvscode-debugger

解决方案


推荐阅读