If your launch script allows you to specify a python target (and finishes quickly enough), you can use pythonArgs in launch.json to insert a shim.

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch via Shell Script",
            "type": "python",
            "pythonArgs": ["debug_shim.py", "launch.sh"],
            "args": ["your", "app", "args"],
            "request": "launch",
            "program": "app.py"
        }
    ]
}

debug_shim.py

import os, subprocess, sys

launcher, debugger, debugger_args = sys.argv[1], sys.argv[2], sys.argv[3:]

sys.exit(subprocess.run(
    args=[launcher] + debugger_args,
    env=dict(os.environ, LAUNCH_TARGET=debugger),
    stdin=sys.stdin,
    stdout=sys.stdout,
    stderr=sys.stderr,
).returncode)

launch.sh

#!/usr/bin/env bash

# Or target could be passed along the command line as well.
# LAUNCH_TARGET="${1?}"

# ...stuff...

python "${LAUNCH_TARGET-app.py}" "${@}"

In my setup of v1.80.0 on WSL2, the debugger call is like so:

python python_args... debugger debugger_args... app app_args...

Then the call stack will be vscode -> shim -> launcher -> debugger -> app and the debugger will connect seamlessly, although if it takes more than several seconds VSCode will time out.

Answer from Merramore on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › python › debugging
Python debugging in VS Code
November 3, 2021 - In such cases, you need to attach the VS Code debugger to the script once it's been launched: Run VS Code, open the folder or workspace containing the script, and create a launch.json for ...
Top answer
1 of 4
2

If your launch script allows you to specify a python target (and finishes quickly enough), you can use pythonArgs in launch.json to insert a shim.

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch via Shell Script",
            "type": "python",
            "pythonArgs": ["debug_shim.py", "launch.sh"],
            "args": ["your", "app", "args"],
            "request": "launch",
            "program": "app.py"
        }
    ]
}

debug_shim.py

import os, subprocess, sys

launcher, debugger, debugger_args = sys.argv[1], sys.argv[2], sys.argv[3:]

sys.exit(subprocess.run(
    args=[launcher] + debugger_args,
    env=dict(os.environ, LAUNCH_TARGET=debugger),
    stdin=sys.stdin,
    stdout=sys.stdout,
    stderr=sys.stderr,
).returncode)

launch.sh

#!/usr/bin/env bash

# Or target could be passed along the command line as well.
# LAUNCH_TARGET="${1?}"

# ...stuff...

python "${LAUNCH_TARGET-app.py}" "${@}"

In my setup of v1.80.0 on WSL2, the debugger call is like so:

python python_args... debugger debugger_args... app app_args...

Then the call stack will be vscode -> shim -> launcher -> debugger -> app and the debugger will connect seamlessly, although if it takes more than several seconds VSCode will time out.

2 of 4
2

Adding the setup scripts to your .bashrc file will ensure that they are sourced before vscode begins debugging your program. The ROS2 documentation supports this method and provides an example.

In your .bashrc file add the following:

source /opt/ros/${ROS_DISTRO}/setup.bash
source ~/ros2_ws/install/local_setup.bash
Discussions

Execute a command in the same shell before debugging
potentially related: https://stackoverflow.com/q/69973202/11107541 . I could swear someone asked a similar question on SO recently. Maybe that was you? More on reddit.com
🌐 r/vscode
3
1
October 5, 2023
visual studio code - How to make VScode launch.json for a Python module - Stack Overflow
I'm researching self-supervised machine learning code. And I have wanted to debug the code with python debugger not pdb.set_trace(). This is python command for ubuntu terminal. python -m torch. More on stackoverflow.com
🌐 stackoverflow.com
Debugging an active python file that creates launch.json is debugging launch.json
Testing #141 Install the debugpy and python extensions Open a folder that has python file. Open the python file. Make sure that you don't have a launch.json config already set. On the top right you will see a play button with an arrow, c... More on github.com
🌐 github.com
0
November 28, 2023
How do I run a Python script on a set of JSON files? - Stack Overflow
I am writing a script that takes 2 JSON files which will just be a basic object of key/value pairs and compare the lengths of the files (number of keys) and well as if the keys are matching. I will... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - When you run json.tool only with an infile option, then Python validates the JSON file and outputs the JSON file’s content in the terminal if the JSON is valid. Running json.tool in the example above means that dog_friend.json contains valid JSON syntax.
🌐
Reddit
reddit.com › r/vscode › execute a command in the same shell before debugging
r/vscode on Reddit: Execute a command in the same shell before debugging
October 5, 2023 -

Hey everyone,

I want to debug a Python Skript using a different arch (x86_64 instead of arm64) then my default terminal. I was looking for ways to define a terminal profile (see also on stackoverflow) using the launch.json, but I haven't found a way yet. I started trying to use the argument preLaunchTask, but this seems to be executed outside of the terminal (and it also freezes for this specific task). Any ideas how to fix this?

// launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python (x86_64): script.py",
            "type": "python",
            "request": "launch",
            "program": "/path/to/script.py",
            "console": "integratedTerminal",
            "justMyCode": true,
            "preLaunchTask": "x86_64"
        }
    ]
}

//tasks.json
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "x86_64",
            "type": "shell",
            "command": "arch -x86_64 zsh"
        }
    ]
}
🌐
DEV Community
dev.to › documendous › run-a-script-before-debugging-your-django-app-in-vscode-475b
Run a Script Before Debugging Your Django App in VSCode - DEV Community
January 4, 2025 - { "version": "2.0.0", "tasks": [ { "label": "Run Pre-Debug Script", "type": "shell", "command": "./setup.sh", "presentation": { "reveal": "always" }, "problemMatcher": [] } ] } ... "presentation": Controls how the output is displayed. Set it to "always" so you can see what’s happening. Next, wire this task into your debugger configuration. Open .vscode/launch.json and edit the Django debugger settings: { "version": "0.2.0", "configurations": [ { "name": "Python Debugger: Django", "type": "python", "request": "launch", "program": "${workspaceFolder}/docrepo/manage.py", "args": [ "runserver", "--noreload", "--nothreading" ], "django": true, "justMyCode": false, "autoStartBrowser": false, "env": { "PYTHONPATH": "${workspaceFolder}/docrepo" }, "preLaunchTask": "Run Pre-Debug Script" } ] }
🌐
GitHub
github.com › microsoft › vscode-python-debugger › issues › 142
Debugging an active python file that creates launch.json is debugging launch.json · Issue #142 · microsoft/vscode-python-debugger
November 28, 2023 - Testing #141 Install the debugpy and python extensions Open a folder that has python file. Open the python file. Make sure that you don't have a launch.json config already set. On the top right you will see a play button with an arrow, c...
Author   sandy081
Find elsewhere
🌐
CodeGenes
codegenes.net › blog › can-i-use-a-vs-code-launch-configuration-to-run-python-without-debugging
How to Run Python Without Debugging in VS Code Using Launch Configuration (launch.json) — codegenes.net
Once launch.json is configured, ... configuration dropdown (top-left), select your custom configuration (e.g., "Python: Run Current File (No Debug)")....
🌐
Stack Overflow
stackoverflow.com › questions › 72594348 › how-do-i-run-a-python-script-on-a-set-of-json-files
How do I run a Python script on a set of JSON files? - Stack Overflow
i.e. I first go through the script for file1.json against config.json, return the desired result, then run the script for file2.json against config.json immediately afterwards.
🌐
Medium
sanborse.medium.com › debugging-python-script-in-vscode-e865b7d6dab5
Debugging Python Script in VSCode | by Santosh Borse | Medium
September 30, 2021 - Open workspace file and add a launch config there as, ... Now you can simply run\debug the code by clicking the green triangle which will run the python code in integrated terminal.
🌐
Python
docs.python.org › 3 › library › json.html
JSON encoder and decoder — Python 3.14.3 documentation
February 23, 2026 - The json module can be invoked as a script via python -m json to validate and pretty-print JSON objects.
🌐
Node-RED
discourse.nodered.org › general
Convert script python to .json file - General - Node-RED Forum
August 7, 2021 - Hello I wrote a scipt in python to detect distance between camera and object, i want to send the distance to an appli node red. Is it possible to convert this script into a .json file and import it into node red to get the readed data into the debug node or into the dashboard ? i've tried to exec the script automatically in node red but it didn"t work Thanks.
🌐
GitHub
github.com › microsoft › vscode-python › discussions › 21837
Change PYTHONPATH before debug · microsoft/vscode-python · Discussion #21837
I am trying to set the PYTHONPATH and other environment variables before launching the debugger. The PYTHONPATH is being set using a shell script, which I managed to run using a task with the preLaunchTask. However, it seems that the PYTHONPATH set by the tasks.json doesn't persist for the terminal used by the launch.json.
Author   microsoft
🌐
Python.org
discuss.python.org › python help
How to make requests_cache store human-readable JSON files that can also serve as debug HTML? - Python Help - Discussions on Python.org
1 day ago - I’m working on an AO3 fanfiction recommender script that makes many HTTP requests to Archive of Our Own. Currently I have two separate systems: SQLite cache (requests_cache) - stores responses to avoid re-fetching Debug HTML files - saves raw HTML to disk with --save-debug-html flag for debugging Current setup Here’s what my client currently looks like: class AO3Client: def __init__(self, use_cache=True, save_debug_html=False): # SQLite cache if use_cache: sel...
🌐
Visual Studio Code
code.visualstudio.com › docs › debugtest › debugging
Debug code with Visual Studio Code
November 3, 2021 - For more complex debugging scenarios like attaching to a running process, you need to create a launch.json file to specify the debugger configuration. Get more information about debug configurations. Choose the debugger you want to use from the list of available debuggers. VS Code tries to run and debug the currently active file. For Node.js, VS Code checks for a start script in the package.json file to determine the entry point of the application.
🌐
Python Land
python.land › home › creating python programs › python in vscode: running and debugging
Python in VSCode: Running and Debugging • Python Land Tutorial
September 5, 2025 - { "version": "0.2.0", "configurations": [ { "name": "Run with argument", "type": "python", "request": "launch", "program": "vscode_playground.py", "console": "integratedTerminal", "args": ["Erik"] } ] }Code language: JSON / JSON with Comments (json) This configuration supplies an argument to the script: the name ‘Erik’. Note that it also specifically starts vscode_playground.py instead of the current file. You can now launch the debugger using this configuration.
🌐
Towards Data Science
towardsdatascience.com › home › latest › a comprehensive guide to debugging python scripts in vs code
A comprehensive guide to debugging Python scripts in VS Code | Towards Data Science
March 5, 2025 - Alternatively, we can use the launch.json config file to provide a set of env variables to the debugging environment. To do so, we press the "gear" icon to open the file and modify it by adding the contents of line 10. When we run the next debugging session, we can directly access the RUN_TYPE env variable, for example, by running the following two lines: ... In this article, I showed how to quickly use VS Code for debugging Python scripts...