9

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.

0

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

1

EDIT: I wrote a new and improved answer to this question here: vscode python remote interpreter

Using the VScode terminal you can run the Python code on a remote machine over SSH with:

cat hello_world.py | ssh user@hostname python - 

You can add this as as your VSCode build task with ${file} pointing to the current file. If you need remote debugging in VScode you can read the following steps: code.visualstudio.com/docs/python/debugging#_remote-debugging

Additionally, you could also create an alias or function in your .bashrc or .zshrc file that makes executing files on a remote machine, potentially in a virtualenv, more convenient. For example, my .zshrc file contains the following function to execute Python files on my workstation in a remote virtualenv:

function remote-pytorch () {
    cat $1 | ssh user@hostname 'source ~/virtualenv/pytorch/bin/activate && python -'
}

This way, I can just run the following command to execute the script remotely:

remote-pytorch train_network.py

(note: the syntax for functions is slightly different in .bashrc files)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.