Reputation: 160
I am writing my first library in Python, When developing I want my run code button in VS Code to always start running the code from the main.py file in the root directory. I have added a new configuration to launch.json however I seem to be unable to use this configuration as default. How can I do this/
Upvotes: 9
Views: 8919
Reputation: 41
I found the right solution is to just change "program" in launch.json to:
"program": "main.py",
If trying to add the {workspaceFolder} it gives a FileNotFoundError.
Upvotes: 3
Reputation: 675
You need to put the 'launch.json
' under the '.vscode
' folder inside your workspace. Then Run
> Run Without Debugging
(shortcut on windows CTRL+F5
)
launch.json
{
// 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": "${workspaceFolder}/main.py",
"console": "integratedTerminal"
}
]
}
Upvotes: 14
Reputation: 2143
You can modify the launch.json
with the below settings for key program
. You may want to point program
to the file which you want to execute. In the below case main.py
is present in my workspace folder only. You can modify it as per your requirement.
{
// 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": "${workspaceFolder}/main.py",
"console": "integratedTerminal"
}
]
}
Upvotes: 5