You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在VSCode中无法调试首个简单Python脚本问题求助

Hey there, sorry you're stuck getting your Python Hello World up and running in VS Code on your Mac. Let's walk through some common fixes that usually resolve this kind of issue.

Troubleshooting Steps

1. Confirm Your Python Interpreter Path is Correct

Macs come with a pre-installed Python 2 version, which often conflicts with newer Python 3 installations. VS Code might be picking the wrong one by default:

  • Press Cmd+Shift+P in VS Code, type Python: Select Interpreter, and choose the Python version you intend to use (look for python3 or a path like /usr/local/bin/python3 instead of the system default /usr/bin/python).
  • If your launch.json specifies a pythonPath, double-check it matches the output of which python3 (run this in your terminal to get the correct path).

2. Validate Your launch.json Configuration

A standard working configuration for running the current file looks like this. Compare it to your provided snippet:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "pythonPath": "${config:python.pythonPath}"
        }
    ]
}
  • Make sure program is set to ${file} (this tells VS Code to run the active script you're editing).
  • Avoid hardcoding a pythonPath unless you're 100% sure it's correct—using ${config:python.pythonPath} will pull the interpreter you selected earlier.

3. Check Your Hello World Script for Basic Errors

Double-check your script doesn't have simple typos (Python is case-sensitive!):

# Correct version
print("Hello World")

# Common mistakes to avoid
Print("Hello World")  # Capital P is invalid
print('Hello World")  # Mismatched quotes

4. Test the Script Directly in Terminal

Rule out VS Code-specific issues by running the script in your Mac's terminal:

  1. Navigate to the folder with your script: cd /path/to/your/script/folder
  2. Run it with your intended Python version: python3 your_script_name.py
    If this works, the problem is definitely in VS Code's configuration. If it fails, you'll get a clear error message to debug your Python environment or script.

5. Verify the VS Code Python Extension is Installed

Make sure you have the official Microsoft Python extension installed and enabled:

  • Open the Extensions panel with Cmd+Shift+X
  • Search for "Python" and confirm the top result (published by Microsoft) is installed and active.

If none of these steps fix the issue, share the exact error message you see in VS Code's terminal/debug console, along with your full launch.json content and script code—this will help narrow down the problem further.

内容的提问来源于stack exchange,提问作者Brad West

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:49:12