简体   繁体   English

获取从特定 python.exe 路径运行的 vscode 调试

[英]get vscode debug running from a specific python.exe path

I try to get VS code debug ( F5 key) to run from the same place as the Run Python File .我尝试让 VS 代码调试( F5键)从与Run Python File相同的位置运行。

The run code path is here:运行代码路径在这里:

c:/Users/Username/.Tactical/Local/envs/lon/python.exe

What i have tired so far (quite a bit from a previous question): run python script in VS code works with run python file button, but not F5 key到目前为止我已经厌倦了(与上一个问题相比): 在 VS 代码中运行 python 脚本适用于运行 python 文件按钮,但不是 F5 键

I now wish to make the launch.json point explicitly to the same path.我现在希望将launch.json明确指向同一路径。

The launch.json configuration looks like this: launch.json 配置如下所示:

{
"name": "Python: Base Console", // i am tesing this.
"type": "python",
"request": "launch",
"program": "${file}",  // can the user change this line to the correct python.exe ?
"console": "integratedTerminal"
}

I tried to change the ${file} to the path, but this failed.我试图将${file}更改为路径,但这失败了。 Have I understood this correctly or what should I do to point to the correct python.exe ?我是否正确理解了这一点,或者我应该怎么做才能指向正确的python.exe

The "program" configuration in launch.json is the entry module of the program. launch.json中的"program"配置是程序的入口模块。

If you want to specify the python interpreter for debugging, use the "python" configuration.如果要指定python解释器进行调试,请使用"python"配置。

A simple example:一个简单的例子:

{
    // 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": ".venv",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "python": "C:\\WorkSpace\\PyTest0628\\.venv\\Scripts\\python.exe"
        },
        {
            "name": "anaconda",
            "type": "python",
            "request": "launch",
            "program": "C:\\WorkSpace\\PyTest0628\\Test6.py",
            "console": "integratedTerminal",
            "justMyCode": true,
            "python": "C:\\Users\\Admin\\anaconda3\\python.exe"
        }
    ]
}

You can choose which configuration to use in the debug window:您可以在调试窗口中选择要使用的配置:

在此处输入图像描述

More configuration information about launch.json : https://code.visualstudio.com/docs/python/debugging#_set-configuration-options有关launch.json更多配置信息: https ://code.visualstudio.com/docs/python/debugging#_set-configuration-options

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM