To execute my python program from the command line, I use sudo python myProgram.py
because my program requires root privileges.
To execute the same from Visual Studio Code IDE, I tried prefixing the pythonPath
variable in launch.json file with the sudo
command but I get the following error:
Error: spawn sudo /usr/local/bin/python3 ENOENT
Here is my task configuration
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "sudo /usr/local/bin/python3",
"program": "${file}",
"cwd": "${workspaceFolder}",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
}
By adding the below configuration now am able to execute with sudo privilege
Sudo in debugOptions and
"console": "externalTerminal",
Here is the complete configuration
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "/usr/local/bin/python3",
"program": "${file}",
"cwd": "${workspaceFolder}",
"console": "externalTerminal",
"env": {},
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput",
"Sudo"
]
},