Debug a local PySpark script in VS Code
Use a breakpoint in your Python driver to inspect the code that builds and runs a Spark job. This walkthrough writes two rows to Parquet, reads them back, and pauses before counting the result.
Start with a working local session
Download the free example below and extract it. Open the extracted pyspark-vscode folder itself in VS Code. Install Microsoft's Python and Python Debugger extensions, then follow the installation guide to create .venv and install the pinned requirements.
Run setup_check.py in the terminal first. You should see Rows written: 2. Resolve an import error or Java startup error before starting the debugger.
Select Python and configure the debugger
Run Python: Select Interpreter from the Command Palette and choose the project's virtual environment. The example includes this .vscode/launch.json file.
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug local PySpark setup",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/setup_check.py",
"console": "integratedTerminal",
"cwd": "${workspaceFolder}",
"justMyCode": true
}
]
}
debugpy selects Microsoft's Python debugger. The program path points to the example, and cwd makes relative paths predictable. The debugger uses your selected Python interpreter. Open this example as the workspace folder so ${workspaceFolder} resolves to the right place.
Pause before the action
Open setup_check.py. Click in the gutter beside rows_written = result.count() to set a breakpoint. In Run and Debug, select Debug local PySpark setup and press F5.
Execution stops before the count runs. In the Debug Console, inspect spark.version, result.columns and result.schema. Press F10 to step over the count, then inspect rows_written. Its value should be 2. Press F5 again to let the script finish and stop Spark.
Understand where the work runs
The Python debugger pauses the driver process. DataFrame operations build a plan that Spark executes through the JVM. A Python UDF runs in a separate Python worker. A breakpoint inside that UDF needs a worker-specific debugging setup and won't behave like a breakpoint in this driver.
Calling collect(), count() or show() in the Debug Console can launch a Spark job. Inspect schema and column names first. Collect only small results that fit in driver memory. Read the lazy evaluation example to see which operations trigger execution.

If a breakpoint stays hollow
Check that you launched the configuration above and that its program path names the file you're editing. Put the breakpoint on an executable statement. A normal terminal run won't attach the debugger. If execution fails before reaching the line, read the first exception in the terminal.
When working in WSL, open the folder in a WSL window and install the extensions into that remote environment when VS Code offers it. Select the WSL virtual environment. Java must be available in that same environment.
Try a deliberate mistake
Temporarily change spark.range(2) to spark.range(3). Step over the count and inspect the value before the assertion runs. You should see 3, followed by an assertion that identifies the mismatch. Restore the range to two and rerun. Each run overwrites the example's own output directory.
Continue with the CSV-to-Parquet tutorial or Microsoft's Python debugging documentation.