Skip to content

VS Code Python debugger stops immediately when using system Python interpreter (works with .venv) #838

@jiajiacaptain

Description

@jiajiacaptain

Bug Report: Python Debugger Stops with "debug stopped" - System Python Only

Issue Summary

The VS Code Python debugger immediately stops with "debug stopped" message when using system Python interpreter, but works correctly with virtual environment (.venv). The issue affects all Python scripts when system interpreter is selected. Scripts run successfully from CMD/PowerShell with both interpreters.

Environment Information

Operating System:

  • Windows 10

VS Code:

  • Version: 1.105.0

Python Extension:

  • ms-python.python (latest)
  • ms-python.debugpy (latest)
  • ms-python.vscode-pylance (latest)

Python Version:

  • 3.11.9
  • System Python: C:\Program Files\Python311\python.exe
  • Virtual Environment: .venv\Scripts\python.exe (same Python 3.11.9)

Steps to Reproduce

  1. Create a simple Python file test.py:
import time
print("debug session started")
time.sleep(10)
print("finished")
  1. Configure VS Code to use system Python interpreter: C:\Program Files\Python311\python.exe

  2. Set up launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "debugpy",
            "request": "launch",
            "module": "test",
            "console": "internalConsole",
            "redirectOutput": true,
            "justMyCode": true
        }
    ]
}
  1. Press F5 to start debugging
  2. Check Debug Console (Ctrl+Shift+Y)

Result with System Python:

  • Debugger immediately shows "debug stopped" dialog
  • Debug Console is empty (no output)
  • Process exits instantly without executing code

Result with Virtual Environment (.venv):

  • ✅ Debugger works correctly
  • ✅ Output appears in Debug Console
  • ✅ Breakpoints work
  • ✅ All debugging features functional

Expected Behavior

Python scripts should debug normally using system Python interpreter, same as with virtual environment.

Actual Behavior

System Python (C:\Program Files\Python311\python.exe):

  • Debugger immediately stops with "debug stopped" message
  • Debug Console remains empty (no output, no errors)
  • No breakpoints hit
  • Process appears to exit before any code executes
  • debugpy log only shows: "Resolving launch configuration with substituted variables"

Virtual Environment (.venv\Scripts\python.exe):

  • ✅ Everything works perfectly
  • ✅ Same Python version (3.11.9)
  • ✅ Same code executes without issues

Additional Context

What Works:

✅ Running from terminal works with both interpreters:

# System Python - works
C:\Program Files\Python311\python.exe test.py

# Virtual environment - works
.venv\Scripts\python.exe test.py

✅ Debugging works perfectly when using virtual environment in VS Code
✅ Code has no syntax errors
debugpy is installed in system Python (pip list shows debugpy-1.8.17)

Key Observation:

The exact same Python version (3.11.9) behaves differently:

  • Virtual environment: debugging works
  • System Python: debugging fails immediately with no error messages

Troubleshooting Steps Already Attempted:

⚠️ ALL attempts failed when using system Python (but work with .venv):

  • ❌ Complete VS Code uninstallation and reinstallation
    • Deleted %APPDATA%\Code and %USERPROFILE%\.vscode
    • Fresh installation
  • ❌ Multiple launch.json configurations tested:
    • "console": "internalConsole" with "redirectOutput": true
    • "console": "integratedTerminal"
    • "console": "externalTerminal"
    • Module-based launch ("module": "..." instead of "program": "...")
  • ❌ Disabled Windows Defender Firewall (all networks)
  • ❌ Disabled Microsoft Defender antivirus
  • ❌ Installed debugpy directly in system Python
  • ❌ Tried different Python scripts (from simple print() to complex imports)
  • ❌ Checked port availability (5678 not in use)
  • ❌ Ran VS Code as administrator
  • ❌ Ran VS Code as normal user

Result: Issue persists with system Python, but virtual environment always works.

Tested Configurations:

// Configuration 1: Internal Console
{
    "name": "Python: System Interpreter",
    "type": "debugpy",
    "request": "launch",
    "program": "${file}",
    "console": "internalConsole",
    "redirectOutput": true,
    "python": "C:/Program Files/Python311/python.exe"
}

// Configuration 2: Module-based
{
    "name": "Python: Module Launch",
    "type": "debugpy",
    "request": "launch",
    "module": "test",
    "console": "internalConsole",
    "redirectOutput": true,
    "python": "C:/Program Files/Python311/python.exe",
    "logToFile": true
}

All configurations fail with system Python but work with .venv\Scripts\python.exe.

Severity

HIGH - Python debugger is unusable when system interpreter is selected, but virtual environment workaround exists.

Impact:

  • Cannot debug with system Python interpreter
  • Forced to create virtual environments for all projects
  • Inconsistent behavior between identical Python versions

Workaround Available:
✅ Using virtual environment (.venv) with same Python version works correctly

Possible Causes

Based on testing, potential issues may include:

  • Python interpreter path handling differences (spaces in path: C:\Program Files\Python311\python.exe)
  • Permission differences between system-wide installation vs. user virtual environment
  • debugpy communication/socket binding issues with system Python
  • VS Code extension unable to properly attach to system Python process
  • Different security contexts between system and virtual environment interpreters

NOT related to:

  • Firewall/antivirus (issue persists with all security disabled)
  • VS Code installation corruption (clean install exhibits same behavior)
  • Python version differences (both use Python 3.11.9)

Diagnostic Information

debugpy log output (system Python):

2025-10-11 13:34:11.377 [info] Resolving launch configuration with substituted variables

(Process exits immediately, no further logs)

Debug Console output:

  • Empty (no output appears)

Terminal execution (both work):

# System Python
PS> C:\Program Files\Python311\python.exe test.py
debug session started
finished

# Virtual environment  
PS> .venv\Scripts\python.exe test.py
debug session started
finished

Workarounds

Effective workaround found:
✅ Use virtual environment with same Python version:

python -m venv .venv
.venv\Scripts\activate
# Now debugging works in VS Code

Ineffective attempts:

  • ❌ Running with "Run Without Debugging" (Ctrl+F5) - Works but no debugging capability
  • ❌ Changing launch.json configurations - No improvement with system Python
  • ❌ Reinstalling VS Code/extensions - No improvement
  • ❌ Installing debugpy in system Python - No improvement

Request

This issue makes system Python interpreter unusable for debugging in VS Code, forcing all workflows to use virtual environments even for simple scripts.

Questions for maintainers:

  1. Why does debugpy work with virtual environment but not system Python (same version)?
  2. Is there a known compatibility issue with system-wide Python installations?
  3. Are there additional logs or diagnostics that could help identify the root cause?

System comparison:

Aspect System Python Virtual Environment
Python Version 3.11.9 3.11.9
Path C:\Program Files\Python311\python.exe .venv\Scripts\python.exe
debugpy installed ✅ Yes (1.8.17) ❌ No (uses bundled)
Debugging ❌ Fails ✅ Works
Terminal execution ✅ Works ✅ Works

Date Reported: 2025-10-11

Metadata

Metadata

Assignees

Labels

triage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions