Visual Studio Code Tips(especially for Remote Jupyter Users)
Main functions
Run And Debug
run current file on workspace root directory
add the below to .vscode/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 Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceRoot}",
"env": { "PYTHONPATH": "${workspaceRoot}"}
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"cwd": "${workspaceRoot}",
"env": { "PYTHONPATH": "${workspaceRoot}"}
},
]
}
Remote Explorer
able to use remote server same way with local. but, can’t use the server that several users use. because git is ambiguous to use
Extensions
IntelliJ IDEA Keybindings
If you want to migrate from Intellij, this will be helpful.
Jupyter
Supported Functions
- Support remote jupyter server
- when vpn is disconnected and reconnected, able to reconnect quickly.
- To run the kernel on different notebook
- To run multiple notebooks at the same time
- To see variables on local/remote server
- To debug on local/remote server
- support kernel completions
- Enable code completions in Notebooks and Interactive Windows using results from the associated Jupyter Kernel.
- To see outline
- Interactive Window
- able to run the selected code of the current python file on interactive window
Jupyter to recognize the specific site-packages
"python.analysis.extraPaths": [
"{your-interpreter-path}/lib/python3.8/site-packages"
],
"python.autoComplete.extraPaths": [
"{your-interpreter-path}/lib/python3.8/site-packages"
]
interactive or jupyter local to run on workspaceRoot
"jupyter.notebookFileRoot": "${workspaceRoot}"
Kernel Completion
"jupyter.enableExtendedPythonKernelCompletions": true,
"jupyter.enableKernelCompletions": true,
run the code of the python file on interactive window
"jupyter.interactiveWindow.textEditor.executeSelection": true
- shortcut name:
Jupyter: Run Selection/Line in Interactive Window
- you can change shortcut by this
Settings
Auto save
VS code’s default saving policy is manual save. for automatic change, you have to change the setting.
"files.autoSave": "afterDelay",
Restore Windows on relaunch
keep existing windows when vscode is relaunched
"window.restoreWindows": "preserve"
Default interpreter path for all projects
no need to set interpreter path for each projects defaultInterpreterPath