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 - For example, you may be debugging a web server that runs different Python scripts for specific processing jobs. 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 that workspace if one doesn't exist already.
🌐
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
Discussions

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
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
tasks.json to execute Python script failing
I created a Python script that takes in parameters that I want to execute locally. Unfortunately, I'm running into an issue where certain Python libraries aren't imported correctly. The err... More on github.com
🌐 github.com
6
December 9, 2021
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
🌐
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 - 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, click the arrow and then click: Python Debugger: Debug using launch.json
Author   sandy081
🌐
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
Debuging...") def check_setting_files(json, config): missing_settings = [] is_matching = False func_settings = return_func_settings(json) config_settings = return_config_settings(config) main_file, sub_file = '', '' if (len(func_settings['settings']) >= len(config_settings['settings'])): main_file = func_settings sub_file = config_settings else: main_file = config_settings sub_file = func_settings for app_setting in main_file['settings']: if (app_setting in sub_file['settings']): is_matching = True else: missing_settings.append(app_setting) print( f"App setting '{app_setting}' doesn't exist in {sub_file['file_name']}") is_matching = False if (is_matching): print( f"The app settings in '{main_file['file_name']}' are in line with '{sub_file['file_name']}'") else: raise Exception( f"App settings: {missing_settings} are missing in '{sub_file['file_name']}'") main()
🌐
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"
        }
    ]
}
🌐
GitHub
github.com › microsoft › vscode › issues › 138825
tasks.json to execute Python script failing · Issue #138825 · microsoft/vscode
December 9, 2021 - As indicated by the comment, running this script through a tasks.json via the default "Ctrl + Shift + B" shortcut for "Tasks: Run Build Task" runs into above import problem. The tasks.json looks like this: { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "Run Python with parameters", "type": "shell", "command": "${command:python.interpreterPath}", "args": ["src\\test.py"], "group": { "kind": "build", "isDefault": true } } ] }
Author   Piranha688
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 74307128 › read-write-local-json-file-using-python-file-executed-by-github-actions-workflow
Read/Write Local JSON file using Python File executed by GitHub Actions Workflow - Stack Overflow
file lives within the same repo as the script. It sounds like you're saying I must pull/push the file within the actions workflow file 2022-11-07T13:02:36.07Z+00:00 ... (1) To get the git-managed files, you should use the github.com/actions/checkout stage, if you're not already using it. (2) Becasue your json file is not git-managed, you need a way to "get" the file from your local repo to the remote github server where your action is running from.
🌐
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.
🌐
Reddit
reddit.com › r/vscode › execute a command before starting debugger.
r/vscode on Reddit: Execute a command before starting debugger.
April 22, 2019 -

Hello guys,

I am debugging djnago using vscode. What i want to do is to activate a virtual environment before the debugger starts so that it can get the environment to run. So is rhere any launch configuration to achieve this?

🌐
GitHub
github.com › gregkurka › midi-to-simplified-json-python
GitHub - gregkurka/midi-to-simplified-json-python: a midi to simplified JSON script I made while working with Kooapps on their game Piano Tiles 2. Requires some editing to the midi via cubase. · GitHub
This script uses mido, a very useful midi library. Before running this script, you use the following functions in Cubase on all notes in the midi file: Simplify tracks down to as few tracks as makes sense. ... Run this python script in the same folder as the new midi files.
Author   gregkurka
🌐
Real Python
realpython.com › python-json
Working With JSON Data in Python – Real Python
August 20, 2025 - To swiftly check if a JSON file is valid, you can leverage Python’s json.tool. You can run the json.tool module as an executable in the terminal using the -m switch.
🌐
Reddit
reddit.com › r/vscode › debugging a python script with arguments in bash
r/vscode on Reddit: Debugging a python script with arguments in bash
December 17, 2021 -

Hello everyone, Vscode noob here.

I have a python script that takes in command line arguments to run, and a bash script that calls the python script with the desired arguments. Now I'm trying to debug the python script with different arguments. I know how to create a launch.json to debug the python part, but AFAIK that involves copying my bash script and reformatting it to .json standards, and since the number of arguments is quite high that takes a while.

So my question is: can I forgo the launch.json directly and debug from the bash script? Or create a launch.json for the bash script (no arguments required for that one) in order to debug the python script? Or is there another way I should be doing this entirely?

🌐
freeCodeCamp
forum.freecodecamp.org › javascript
(absolute beginner) how do I run a Python script & how do I edit JSON?
June 20, 2020 - Hi guys, This is properly easy to do but i have no idea how to do it. So I downloaded something from GitHub that is supposed to help me find codes on a websites. The instructions are following: After running edit: $HOME/.config/crunchyroll-guest-pass-finder/accounts.json The JSON file is an array of dictionaries containing the following fields Fields are: Username - username of the account Password - password of the account Active (optional) - if set and false, then the account is ignor...
🌐
Donjayamanne
donjayamanne.github.io › pythonVSCodeDocs › docs › debugging
Debugging | Python in Visual Studio Code
Debugging a standard python application is possible by adding the standard configuration settings in the launch.json file as follows:
🌐
GitHub
github.com › marketplace › actions › run-python-script
Run Python Script - GitHub Marketplace
name: Run Script on: push: jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 with: python-version: '3.x' - uses: jannekem/run-python-script-action@v1 id: script with: fail-on-error: false script: | print("Doing something that will fail") a = [] a[10] - name: Print errors if: steps.script.outputs.error == 'true' run: | printenv "SCRIPT_STDOUT" printenv "SCRIPT_STDERR" env: SCRIPT_STDOUT: ${{ steps.script.outputs.stdout }} SCRIPT_STDERR: ${{ steps.script.outputs.stderr }}
🌐
GitHub
github.com › microsoft › vscode-jupyter › wiki › How-python-debugging-works
How python debugging works · microsoft/vscode-jupyter Wiki
Contains the data in the launch.json. In debugpy's case, this would be python interpreter to use, the script to debug, arguments, environment, and a bunch of other flags. Set Breakpoints - Breakpoints are sent prior to a 'configurationDone' message so that the process has all of its breakpoints before the debugging actually starts
Author   microsoft