Visual Studio Code中Python调试异常:变量窗口无内容
Hey there! Let's work through why your VS Code debugger isn't displaying variables when running your Python 3.6.4 scripts. I've dealt with similar quirks before, so here are some practical fixes to try:
Double-check your selected Python interpreter
Open the command palette (pressCtrl+Shift+Pon Windows/Linux,Cmd+Shift+Pon Mac), search forPython: Select Interpreter, and confirm you've picked your exact Python 3.6.4 installation. VS Code sometimes auto-selects a different environment or version, which breaks the debugger's ability to track variables.Verify your launch configuration
Open the.vscode/launch.jsonfile (if you don't have one, click "create a launch.json file" in the debug panel and select Python). Your "Python: Current File" config should look like this:{ "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true } ] }Ensure
programis set to${file}(so it targets your open script) andjustMyCodeis enabled (this focuses on your variables instead of library code).Make sure you've set a breakpoint
Without a breakpoint, your script will run straight to completion before the debugger can load and display variables. Click the blank space left of a line number in your code to add a red breakpoint dot—try placing it right after you define some variables, then start debugging again.Update VS Code and the Python extension
Your VS Code version (1.23.1) is pretty outdated, and older versions often have compatibility bugs with Python interpreters. Upgrade VS Code to the latest release, then head to the extensions panel and update the Microsoft Python extension (the one with the blue logo). This alone fixes most old debugger issues.Test with a minimal script
Create a super simple test script to rule out issues with your original code:test_var = 42 greeting = "Hello, debugger!" print(test_var, greeting)Add a breakpoint on the
printline, start debugging, and check iftest_varandgreetingshow up in the variables panel. If they do, your original script might have variables that aren't being executed (e.g., inside an unreachableifblock) or optimized away.Check the variables panel visibility
Sometimes the variables panel gets accidentally hidden or collapsed. In the debug sidebar (left side of VS Code when debugging is active), make sure the "Variables" tab is selected and expanded—you should see your local and global variables listed there once the breakpoint hits.
内容的提问来源于stack exchange,提问作者caddie

