UV VS Code Task
To create a shortcut in VS Code for running your Python script with uv, follow these steps:
1. Open Keyboard Shortcuts
- Press
Ctrl+Kfollowed byCtrl+Sto open the Keyboard Shortcuts menu.
2. Add a New Shortcut
- In the search bar at the top, type
run task. - Find the command
Tasks: Run Taskand click on the pencil icon next to it to add a new keybinding. - Choose a key combination that you want to use (e.g.,
Ctrl+Alt+R).
3. Configure the Task
- Open the Command Palette by pressing
Ctrl+Shift+P. - Type
Tasks: Configure Taskand select it. - Choose
Create tasks.json file from templateand then selectOthers.
4. Edit tasks.json
- VS Code will open a
tasks.jsonfile. Replace its content with the following configuration:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Python Script with uv",
"type": "shell",
"command": "uv run python ${file}",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"problemMatcher": []
}
]
}
5. Use the Shortcut
Now, you can use the key combination you set (e.g., Ctrl+Alt+R) to run your Python script with uv.
This setup will allow you to quickly run your Python scripts using uv with a simple keyboard shortcut. Let me know if you need any further assistance!