Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode python debug with arguments syntax error in launch.json

I followed the microsoft doc and tried the following SO post. Currently I'm debugging via Python: Current File, and my launch.json is as follow:

{
    // 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",
            "args": ["saveData","-s","XYZ"]
        }
    ]
}

and I'm experiencing the following error

File "/home/XD/miniconda3/envs/drl/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
File "/home/XD/miniconda3/envs/drl/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
...
File "/mnt/c/Users/XD/Documents/folder.vscode/launch.json", line 2
    // Use IntelliSense to learn about possible attributes.
     ^
SyntaxError: invalid syntax

My main script is as follows:

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Choose Task')
    subparser = parser.add_subparsers(dest='subcommand',help='sub-command help')
    parser_sd = subparser.add_parser("saveData")
    parser_sd.add_argument('-s','--Symbol', type=str, required=True)
    parser_sd.add_argument('-f','--fileDest',type=str,default=None)

What is wrong with it?

like image 867
smaillis Avatar asked Jun 14 '26 18:06

smaillis


1 Answers

This is an easy mistake to make: you edit the launch.json file, then start debugging and get the error you mentioned. It means that you're trying to run/debug the launch.json file itself, rather than your code.

Switch to the tab containing your code, then start debugging.

(as mentioned by @rioV8 in the comments, but this is an easy enough mistake to make that it seems worth an answer).

like image 154
jdigital Avatar answered Jun 17 '26 09:06

jdigital



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!