I think the --City and Auckland are used as a single argument. Maybe try separating them like so...

Single argument

"args": ["--city","Auckland"]

Multiple arguments and multiple values

Such as:

--key1 value1 value2 --key2 value3 value4

Just put them into the args list one by one in sequence:

"args": ["--key1", "value1", "value2", "--key2", "value3", "value4"]
Answer from Pawan kumar on Stack Overflow
🌐
GitHub
github.com › microsoft › vscode › issues › 149391
vscode adding escapes to args supplied via launch.json configuration. python sys.argv sees VS code's arguments not those specified in launch.json. · Issue #149391 · microsoft/vscode
May 12, 2022 - Create a new Python script display_argv.py with the source code shown below. Choose Run/Add Configuration or start debugging display_argv.py to kick off a prompt that ultimately causes a default launch.json to be created. In the launch.json, add an "args" field with an array containing a single arg element of "C:\". Note, in the example launch.json shown below, there are two slashes which are required by VSCode to satisfy its syntax checker since json requires escaping slash (and fwiw, VSCode fails to launch the script without escaping the slash).
Published   May 12, 2022
Author   AshleyT3
Discussions

Certain strings set in the launch.json "args" will not be passed to python as arguments
Environment data VS Code version: 1.47.2 Extension version (available under the Extensions sidebar): 2020.7.94776 OS and version: macOS Catalina 10.15.5 Python version (& distribution if applic... More on github.com
🌐 github.com
5
July 23, 2020
Arguments in launch.json not being used
My current workspace directory is path/to/project. Here is what is in this directory: .vscode/ | launch.json figures/ scripts/ | test_chdir.py ... { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python... More on github.com
🌐 github.com
1
December 18, 2022
python - VS Code not picking up args list from launch.json - Stack Overflow
I have a basic python file that I'm experimenting with. I want to launch it with two args in vs code. I've opened the launch.json file from the command window (ctrl+shift+p) but on each run it fail... More on stackoverflow.com
🌐 stackoverflow.com
visual studio code - Specifying arguments in launch.json for Python - Stack Overflow
Mind that providing arguments in launch.json works like described until you need key/value pair args. ... Find a nearly hidden hint in the "Watson" example in Python debug configurations in Visual Studio Code. ... Sign up to request clarification or add additional context in comments. ... Thanks for the answer! For everyone wondering, if you need to add paths you might have to change "\" to "/" otherwise VSCode might not ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › microsoft › vscode › issues › 139251
VS Code does not use launch.json arguments when I press Debug Python File · Issue #139251 · microsoft/vscode
December 16, 2021 - If I open the Run&Debug pane and then press on the button circled in green with the right profile, it works · What is really baffling to me is nowhere in the documentation does it state the Debug Python file button does not pass arguments. Is there a way to force that button to use my launch.json?
Author   ejkitchen
🌐
Visual Studio Code
code.visualstudio.com › docs › python › debugging
Python debugging in VS Code
November 3, 2021 - By default, the debugger uses the same interpreter selected for your workspace, just like other features of Python extension for VS Code. To use a different interpreter for debugging specifically, set the value for python in launch.json for the applicable debugger configuration.
🌐
GitHub
github.com › microsoft › vscode-python › issues › 13111
Certain strings set in the launch.json "args" will not be passed to python as arguments · Issue #13111 · microsoft/vscode-python
July 23, 2020 - Relevant/affected Python-related VS Code extensions and their versions: N/A ... Putting "\s" anywhere in an argument in the "args" list of the launch.json file will then pass that argument "\s" to the python file I'm debugging
Author   jeb5
🌐
GitHub
github.com › microsoft › vscode-python › issues › 20396
Arguments in launch.json not being used · Issue #20396 · microsoft/vscode-python
December 18, 2022 - My current workspace directory is path/to/project. Here is what is in this directory: .vscode/ | launch.json figures/ scripts/ | test_chdir.py ... { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true, "cwd": "${fileDirname}" } ] }
Author   mhdadk
Find elsewhere
🌐
GitHub
github.com › microsoft › vscode-python › issues › 21364
arguments in launch.json is not used when click "Run Python File" button in the top right of the window · Issue #21364 · microsoft/vscode-python
June 4, 2023 - { "name": "Python: test", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true, "purpose": [ "debug-in-terminal" ], "args": [ "/foo/bar/abc.txt" ] }, ... Python version (& distribution if applicable, e.g. Anaconda): 3.8.10 · Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Global · Value of the python.languageServer setting: Default
Author   carpetaa
🌐
Reddit
reddit.com › r/vscode › python debugging command line incorrect with using arguments
r/vscode on Reddit: Python Debugging Command Line Incorrect with Using Arguments
May 7, 2024 -

Hi All,

I am sure I am missing something obvious, and VSCODE works great for me when debugging Python in WSL2 on my Windows 11 machine. But today I wanted to debug Python on Windows and I ran into an issue when trying to debug with arguments. I can debug fine if I click after the arrow and select Python Debugger: Debug Python File. The command line string that appears in the terminal is formatted just fine, and everything works great. But when I choose Python Debugger: Debug using launch.json, I get asked for another choice from a list... I choose Python Debugger: Current File with Arguments and that is when I get my error in the terminal. The command line string is not formatted correctly.

Here is the command line when I choose my first option "Python Debugger: Debug Python File"...

C:\Creative Imagination\code\python3\MediaTools\scripts> c: && cd "c:\Creative Imagination\code\python3\MediaTools\scripts" && cmd /C ""c:\Program Files (x86)\Python312-32\python.exe" c:\Users\hopwo\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 60752 -- "C:\Creative Imagination\code\python3\MediaTools\scripts\fonts.py" "

And here is the command line when I choose my second option "Python Debugger: Current File with Arguments... launch.json"

c:\Creative Imagination\code\python3\MediaTools\scripts> c: && cd "c:\Creative Imagination\code\python3\MediaTools\scripts" && cmd /C "c:\Program Files (x86)\Python312-32\python.exe c:\Users\hopwo\.vscode\extensions\ms-python.debugpy-2024.0.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher 61165 -- C:\Creative Imagination\code\python3\MediaTools\scripts\fonts.py "

Notice the difference in the quotes at the end, and after '&& cmd /C'. The command-line string is formatted differently.

I have been trying for hours to find where I can edit how the command line string is constructed but I cannot find an option for that anywhere. All I can do is edit the launch.json, and I see no clues with...

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: 
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: Current File with Arguments",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": "${command:pickArgs}"
        },
    ]
}

It's not a big deal really... I write most of my Python stuff in WSL2-Ubuntu and using VSCODE with the remote connection works great for me with both types of debugging. The only reason I moved out of WSL to Windows is because I am learning TKinter and in WSL, I only had one font to pick from. When I tried my test code in Windows (outside of WSL2) I had 911 fonts to choose from. This is where I ran into my debugging issue.

Thanks for listening! I hope my oversite is not too obvious.

Top answer
1 of 1
24

Update May 2022 from Microsoft tech support on github issues for vscode-python

You need to add this section to your launch.json file: "purpose": ["debug-in-terminal"]

I just tested it on VS Code 1.67.1 and it works. The documentation appears to state that if you add this "flag" then F5 or Run > Debug won't use the launch.json settings but they do. I have asked them to update their docs to make this clearer as it is confusing.

============

I filed a bug with the Microsoft VS Code team regarding this issue and they sent me over to the Microsoft Python extension group. I then filed a bug there referencing the VC Code ticket and it was immediately assigned for "area-debugging triage". I presume this will be fixed in a later version (I am on 1.63.2)

First, it is not obvious where this button comes from. I have noted this issue as well with Microsoft so they can improve their documentation. When you install VS Code with no extensions, this button is not present. But as soon as you load your first Python file, Microsoft urges you to install the official "Microsoft Python Extension" and then the button shows up. In my mind, I assumed this was a native VS Code button that showed up when you had a language debugger installed. When I removed all extensions, except the Microsoft Python extension, I was convinced this was part of VS Code.

The answer above incorrectly states that this is the correct behaviour for the button. It is not. Microsoft has confirmed this and if you read issue #2338 ("Documentation for python.terminal.launchArgs is unclear") there is a response in there stating:

"Unfortunately that's just how vscode works. When debugging all settings are read from launch.json and non-debugging settings.json is used This applies to all languages (extensions) in vscode."

So for now, there is nothing much to do other than wait for this to be fixed.

Lastly, for those who are wondering why I wanted to use that button in the first place. For the most part, I use keyboard mappings to start debugging when I am inside VS Code. But for this particular project, I was going to other external windows and when coming back to VS Code, since I was already using the mouse, I just wanted to click there out of convenience. I don't keep the debug tab open which also has a debug button that works as intended.

🌐
GitHub
github.com › microsoft › debugpy › issues › 739
Debugging a python module: args in launch.json not being passed to python program correctly, "unrecognized switch" · Issue #739 · microsoft/debugpy
October 4, 2021 - Usage: debugpy --listen | --connect [<host>:]<port> [--wait-for-client] [--configure-<name> <value>]... [--log-to <path>] [--log-to-stderr] <filename> | -m <module> | -c <code> | --pid <pid> [<arg>]... Error: unrecognized switch --verbose · I'm basically having the issue described here: microsoft/vscode#2167 except, I'm definitely not making the same error. ... I would think my launch.json should be able to pass the --verbose, --file-to-write arguments correctly to the debugger and allow it to boot.
Author   bbiney1
🌐
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: { "name": "Python", "type": "python", "pythonPath":"${config.python.pythonPath}", "request": "launch", "stopOnEntry": true, "console": "none", "program": "${file}", "cwd": "${workspaceRoot}", "debugOptions": [ "WaitOnAbnormalExit", "WaitOnNormalExit", "RedirectOutput" ], "env": {"name":"value"} }
🌐
GyanBlog
gyanblog.com › home › vs-code - how to debug and pass command line arguments via launch config
VS-Code - How to Debug and pass Command Line Arguments via Launch Config | GyanBlog
February 16, 2021 - { "version": "0.2.0", "configurations": [ { "name": "Python: Any_Name", "type": "python", "request": "launch", "program": "${workspaceFolder}/app.py", "args": [ "-c", "/Users/xyz/config", "-p", "2012" ] } ] }
🌐
Reddit
reddit.com › r/vscode › [deleted by user]
I just can't get command line arguments in launch.json ...
April 22, 2022 - I was pressing the main run button but that one doesn't take the launch.json into account. You need to open the Run and Debug pane by clicking on the button on the bar on the left and then click the run button in the pane that opens. Check the screenshot above to see which button you need to ...
🌐
Reddit
reddit.com › r/vscode › passing a json in launch.json args?
r/vscode on Reddit: passing a json in launch.json args?
May 31, 2022 -

how do I send a json as an input argument (for python) in the launch.json config file?

the issue is launch.json is already a json so it has to be formatted:

"args": [ "somearg=json_here"]

but i cant pass a json that starts with "

Has anyone successfully dealt with this json in a json problem?

🌐
GitHub
github.com › microsoft › vscode-python › issues › 10456
JSON object parsing "problem" in launch.json · Issue #10456 · microsoft/vscode-python
March 5, 2020 - { "version": "0.2.0", "configurations": [ { "name": "Test training", "type": "python", "request": "launch", "program": "${cwd}/main.py", "console": "integratedTerminal", "env":{ "LANG": "C.UTF-8" }, "args": [ "--mode", "train" "--data-dir", "./data/msg", "--output-dir", "./tmp_output", "--dataset", "some_dataset" ] } ] } (Note that a comma is missing after "train",, which means that the json object is invalid.