簡體   English   中英

獲取從特定 python.exe 路徑運行的 vscode 調試

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

我嘗試讓 VS 代碼調試( F5鍵)從與Run Python File相同的位置運行。

運行代碼路徑在這里:

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

到目前為止我已經厭倦了(與上一個問題相比): 在 VS 代碼中運行 python 腳本適用於運行 python 文件按鈕,但不是 F5 鍵

我現在希望將launch.json明確指向同一路徑。

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"
}

我試圖將${file}更改為路徑,但這失敗了。 我是否正確理解了這一點,或者我應該怎么做才能指向正確的python.exe

launch.json中的"program"配置是程序的入口模塊。

如果要指定python解釋器進行調試,請使用"python"配置。

一個簡單的例子:

{
    // 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"
        }
    ]
}

您可以在調試窗口中選擇要使用的配置:

在此處輸入圖像描述

有關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