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 OverflowI 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"]
I also noticed that if you run the script by clicking on the debug button that looks like this
, then the arguments are not passed. However, using Run -> Start Debugging (or its shortcut F5) passed the arguments successfully.
Certain strings set in the launch.json "args" will not be passed to python as arguments
Arguments in launch.json not being used
python - VS Code not picking up args list from launch.json - Stack Overflow
visual studio code - Specifying arguments in launch.json for Python - Stack Overflow
Videos
Its probable that vscode isn't picking up your launch configurations. Just a few sanity checks:
Did you confirm that launch.json is located in .vscode/ ?
In addition - did you make sure that you have the right configuration selected when you go to run? In this case: "Python: Current File".
launch configuration
What worked for me,provided you already have a launch.json file, press Ctrl+Shift+D, Select Python Debugger, Click on "Open launch.json" icon (crank icon), make sure the you have:
"name": "Python Debugger: Current File",
Note:No other name will work, and you have your arguments:
"args": [ "--config", "config.cnf", "--configPath", "configArchive/cc/" ]
Then it should pick up your arguments
There is also an option, when you open your python file, you need to select "Python Debugger: Debug using launch.json"
(I see it was indicated above as well in comments :-))
Shortcut key: F5
Mind that providing arguments in launch.json works like described until you need key/value pair args.
For example, the command
$ python main.py --verbose --name Test
has to be coded inside the launch.json arguments line like this:
"args": ["--verbose", "--name=Test"],
Find a nearly hidden hint in the "Watson" example in Python debug configurations in Visual Studio Code.
AAargh.. I just wasted 30 minutes of my life trying to figure out how to clearly define arguments with values. Sometimes things worked and sometimes total fail. I was just looking at the last error message: // Use IntelliSense to learn about possible attributes.
Turns out I had both my python program and the file launch.json active in the VScode open editor. I was making changes to launch.json, but FAILING to click on my python file before starting up the debugger.
Doh! Its not a surprise that a python interpreter fails when trying to run a .json file. Need to carefully read the complete error message. (The error message should say... hey you big dummy.. you should be using a .py file when executing python!)
Info shared here in case anybody else makes the same dumb mistake.
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.
Does VSCode have a way of doing [title], either natively or through an extension?
I can manage it fine using `launch.json`, but sometimes I want to be able to pass in CLI arguments and not be in debug mode.
I'm aware of the workarounds of "Run it via the command-line" and "Hardcode the args in the file", but neither is a good solution to be honest, and this feels like an incredibly basic feature to be missing.
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?