DEV Community

dss99911
dss99911

Posted on • Originally published at dss99911.github.io

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}"}
        },
    ]
}
Enter fullscreen mode Exit fullscreen mode

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"
]
Enter fullscreen mode Exit fullscreen mode

interactive or jupyter local to run on workspaceRoot

"jupyter.notebookFileRoot": "${workspaceRoot}"
Enter fullscreen mode Exit fullscreen mode

Kernel Completion

"jupyter.enableExtendedPythonKernelCompletions": true,
"jupyter.enableKernelCompletions": true,
Enter fullscreen mode Exit fullscreen mode

run the code of the python file on interactive window

"jupyter.interactiveWindow.textEditor.executeSelection": true
Enter fullscreen mode Exit fullscreen mode
  • 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",
Enter fullscreen mode Exit fullscreen mode

Restore Windows on relaunch

keep existing windows when vscode is relaunched

"window.restoreWindows": "preserve"
Enter fullscreen mode Exit fullscreen mode

Default interpreter path for all projects

no need to set interpreter path for each projects
defaultInterpreterPath

Code Runner

현재 활성화된 파일을 실행 시켜준다.


Originally published at https://dss99911.github.io

Top comments (0)