Search code examples
pythonconfigurationvisual-studio-coderemote-debuggingssh-tunnel

Configuring Visual Studio Code for remote Python interpreter via SSH


I have a Vagrant box with ArchLinux and Python which uses a virtual environment per project (by using a certain Python version). I wish to configure VSC for running/debugging these Python projects. I've mounted the directory containing my projects (with sshfs) so I don't have to worry about sync.

With PyCharm the configuration is only in its IDE. How can I configure it for VSC by using SSH? What are other plugins necessary to work with Python?

Thanks in advance.

PS1: PyCharm is a great tool but it takes much resources, near 1GB in RAM.

PS2: I've read this article but it is not clear for me, one example is more useful.


Solution

  • The post Define remote interpreter on remote Linux machine using Pydev and RSE Server was really useful, it seems so obvious now. This is my workaround using my own system configuration:

    Step 1: Mount your remote home folder.

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

    Step 2: Open your project folder with VSC.

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

    Step 3: Configure "settings.json" (from WorkSpace Settings) for your remote Python and linter.

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

    Step 4: Enjoy programming. You are welcome.