In my folder folder1
I have a python venv which I have activated in my terminal with source .venv/bin/activate
.
Then, I run my python file in the terminal using python3.12 file1.py
How do I run this through VS Code's launch.json
?
In my folder folder1
I have a python venv which I have activated in my terminal with source .venv/bin/activate
.
Then, I run my python file in the terminal using python3.12 file1.py
How do I run this through VS Code's launch.json
?
Install the python extension for vscode python extension
on the bottom right corner where the python version appears click on it and it will prompt you to chose the python interpreter you want to use. Select the one associated with your virtual environment. chose interpreter
now press f5 and it will prompt you to select a debugger. Since you have installed the python extension you should see the python debugger appear. Select python debugger. select a debugger
next you will have to select debug configuration. You can choose according to what you are building or which framework you are using. In your case you are running a python file. The first choice will do. debugger configuration
this will run your file. Then on the left panel on the debug window click on the link that says create launch.json file. create launch.json file
go through the same process as before, select a debugger then select a debugger configuration then this will create a launch.json file for you according to the debugger and its configuration.
{
// 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 Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}