vscode python remote interpreter

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

By using VSCode (Visual Studio Code) I execute Python code on a local Python (Anaconda) interpreter. Now I would like to set it up so that I am able to execute that code on a remote Python interpreter. I have a Linux device which has its own Python and is accessible via ssh.
Is it possible to configure it? If so how? Thank you.

回答1:

While Microsoft is working on officially implementing this in VSCode (see: https://github.com/Microsoft/vscode-python/issues/79) I am personally using the following task defined in tasks.json for running Python on my remote machine. It contains two tasks: (1) synchronize the code to the remote machine using rsync; (2) execute the code over SSH in the remote interpreter. Note that the execution task dependsOn the sync task so that executing the code is always done from the latest local copy.

{     "version": "2.0.0",     "tasks": [         {             "label": "Synchronize Code",             "type": "shell",             "command": "rsync -axv --exclude-from=rsync-exclude.lst --max-size=5MB \"${workspaceFolder}\" user@hostname:dev/code-sync/",             "problemMatcher": [],             "isBackground": true,             "presentation": {                 "echo": false,                 "reveal": "silent",                 "focus": false,                 "panel": "shared",                 "clear": false             }         },         {             "label": "Remote Execute",             "type": "shell",             "command": "ssh -n user@hostname \"source ~/.profile && source /path/to/virtualenv/bin/activate && python ~/dev/code-sync/${workspaceFolderBasename}/${relativeFile}\"",             "dependsOn": [                 "Synchronize Code"             ],             "problemMatcher": []         }     ] }

Note that you can also assign a keybinding to executing the task so that you can execute the Python code on the remote with a single keypress. Add to keybindings.json:

{     "key": "cmd+shift+r",     "command": "workbench.action.tasks.runTask",     "args": "Remote Execute" }


转载请标明出处:vscode python remote interpreter
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!