vscode: debugging python scripts with args

diary of a codelovingyogi
1 min readMar 11, 2020

--

On the top, left side of VSCode, find your debugsettings files by going to the gear icon.

In launch.json you should see pre-populated settings that looks something like:

{// 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 (Integrated Terminal)",            "type": "python",            "request": "launch",            "program": "${file}",            "console": "integratedTerminal"        },    ]}

For scripts, that require args you can update the json configuration to look something like this:

"configurations": [    {        "name": "Python: Current File (Integrated Terminal)",        "type": "python",        "request": "launch",        "program": "/Users/<username>/<path>/<to>/<file>/<file_name>.py",        "console": "integratedTerminal",
"args": ["-p","<project_name>", "-k", "<key_name>"]
},]

If you get an error that a Python Interpreter is missing:

You need to select a Python interpreter before you start debugging. Tip: click on "Select Python Interpreter" in the status bar.

You can fix it by making sure that there is a virtual environment in the same root directory you are using the debugger. VSCode will auto-detect and activate the venv for you, and then know which Python interpreter to use.

--

--