簡體   English   中英

VS 代碼中的 Python:不在斷點處停止

[英]Python in VS Code: Not stopping at breakpoints

我正在嘗試調試一個簡單的 Python 程序,該程序讀取 CSV 並在 VS Code 中寫入一個新程序。 當我設置斷點時,它會被跳過。 我能夠使用breakpoint()並獲得基本的 Python 調試器,但我更喜歡能夠使用 VS Code 調試器。 我找到了這個SO 帖子這個文檔,但都沒有解決這個問題。 我在 Windows、Python 版本 3.9.1。 我不是經驗豐富的 Python 開發人員,所以我很可能遺漏了一些明顯的東西,但我已經完成了 .NET 開發的公平份額。

更新 1: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",
            "stopOnEntry": true,
            "justMyCode": false
        }
    ]
}

對於代碼,我在各處設置了斷點以使其正常工作,但這是我的main.py 我在h.get_approvers()行上嘗試了一個斷點:

import adp
import hierarchy
import expensify
import sys

h = hierarchy.Hierarchy()
h.get_approvers()

更新2:調試時終端output

Loading personal and system profiles took 664ms.
PS C:\Users\...\OneDrive - ZoomInfo\Dev\Sandbox\PyTest> & C:/Python39/python.exe "c:/Users/.../OneDrive - ZoomInfo/Dev/Sandbox/PyTest/main.py"        
Hello world
PS C:\Users\...\OneDrive - ZoomInfo\Dev\Sandbox\PyTest>

更新問題已關閉,我已收到確認它與Python version 3.9.3 (64 bit)有關。

https://github.com/microsoft/vscode-python/issues/15865

原帖

這一直讓我發瘋,需要進一步調查,但我注意到

Python 3.9.3 64 bit >> 跳過斷點

Python 3.9.2 64 bit >> 按預期工作

我已經多次復制了這個,只是為了確保我不只是通過簡單的卸載/重新安裝來解決問題。

我為此提出了一個問題,一旦找到正確的根本原因,我會立即更新此回復,但現在這最終解決了我的問題……盡管我並不滿意。

https://github.com/microsoft/vscode-python/issues/15865

我注意到在您提供的終端信息中,使用的唯一路徑是“python.exe”和文件“main.py”路徑。

在VS Code中,Python代碼的調試function由Python擴展提供。 因此,在調試 python 腳本時,會使用“python 解釋器”( python.exe )、“python 擴展”( .vscode\extensions\ms -python.python-2021.1.502429796\pythonFiles\lib\python\debugpy ) “python 腳本”( .py file )。

當我點擊VS Code右上角的綠色運行按鈕時,VS Code終端顯示的路徑只有python.exe".py" file :運行代碼,不會停留在斷點處。

在此處輸入圖像描述

當我單擊F5或“ Start Debugging ”按鈕時:調試代碼將停留在斷點處。

在此處輸入圖像描述

如果還是不行,請嘗試重新安裝 Python 擴展並重新加載 VS Code。

參考: Python 在 Visual Studio Code 中調試

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM