3

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?

2
  • 2
    it looks like you are trying to execute the launch.json Commented Aug 25, 2020 at 16:24
  • @smaillis Have you ever tried to run this script in the cmd window? Can it run successfully or does the same issue occur? It is recommended that you could check the code writing and format. In addition, it will be better solved if you could provide complete code information, especially the codes near code lines 85 and 193. Commented Aug 26, 2020 at 5:56

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

1 Comment

FACE. PALM. Also, EYE. ROLL. I'm really hoping there's a way to prevent this by setting up a particular file to be debugged or something like that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.