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.
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

Change PYTHONPATH before debug
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 ... More on github.com
๐ŸŒ github.com
3
2
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 10, 2021
๐ŸŒ
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
๐ŸŒ
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
๐ŸŒ
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 10, 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.
June 11, 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?

๐ŸŒ
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.
๐ŸŒ
Mechanicalgirl
mechanicalgirl.com โ€บ post โ€บ using-gitHub-actions-run-python-script
Using GitHub Actions to run a Python script - Mechanicalgirl.com
November 25, 2024 - jobs: generate-pull-request: name: Generate Pull Request runs-on: ubuntu-latest outputs: changes: ${{ steps.git-check.outputs.changes }} steps: - name: Check out repository to the runner uses: actions/checkout@v4 with: fetch-depth: 0 - name: configure git run: | git config user.name github-actions git config user.email github-actions@github.com git checkout main git fetch origin - name: setup python uses: actions/setup-python@v5 with: python-version: 3.12 - name: Run script run: python3 .github/scripts/keys.py - name: check for changes id: git-check run: | if git diff --quiet; then echo "No ch
๐ŸŒ
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:
๐ŸŒ
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...
๐ŸŒ
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
January 17, 2022 -

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?

๐ŸŒ
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 }}