首页 > 解决方案 > 通过 SSH 为远程 Python 解释器配置 Visual Studio Code

问题描述

我有一个带有 ArchLinux 和 Python 的 Vagrant 盒子,每个项目使用一个虚拟环境(通过使用某个 Python 版本)。我希望配置 VSC 以运行/调试这些 Python 项目。我已经安装了包含我的项目的目录(使用sshfs)所以我不必担心同步。

使用 PyCharm,配置仅在其 IDE 中。如何使用 SSH 为 VSC 配置它?使用 Python 还需要哪些其他插件?

提前致谢。

PS1:PyCharm 是一个很棒的工具,但它需要很多资源,接近 1GB 的 RAM。

PS2:我读过这篇文章,但我不清楚,一个例子更有用。

标签: pythonconfigurationvisual-studio-coderemote-debuggingssh-tunnel

解决方案


使用 Pydev 和 RSE 服务器在远程 Linux 机器上定义远程解释器的帖子非常有用,现在看起来很明显。这是我使用自己的系统配置的解决方法:

第 1 步:挂载您的远程主文件夹。

$ sshfs -o password_stdin,transform_symlinks vagrant@localhost:/home/vagrant ~/Vagrant/archi02/Remote/ -p 2222 <<< "your_vagrant_password"

第 2 步:使用 VSC 打开您的项目文件夹。

~/Vagrant/archi02/Remote/Projects/Python_3_7_2/QuickPythonBook/

第 3 步:为您的远程 Python 和 linter配置“ settings.json ”(来自WorkSpace Settings )。

{
    "python.pythonPath": "~/Vagrant/archi02/Remote/Projects/Python_3_7_2/QuickPythonBook/ve_qpb/bin/python3.7",
    "python.linting.pylintEnabled": true,
    "python.linting.pylintPath": "pylint"
}

第 4 步:享受编程。不客气。


推荐阅读