5

I am having my remote(ubuntu 16.04) drive mounted on my local system(ubuntu 16.04) so that I can edit the source files by opening them in vscode.

Also, in the integrated terminal I can ssh to remote system and run the program using remote python interpreter which is installed on virtual environment like:

$ssh username@remoteip    
$workon remotevirtualenv
(remotevirtualenv)$python source.py

I want to enable remote debugging so that if I run the debug/run the remote files, the vscode which is installed on my local system uses my remote python interpreter.

I went through the docs suggesting the use of ptvsd extension(which asks to have 2 copies of source files one on local, another one server) but I am not sure how to configure it in this scenario. Appreciate the help. Thanks.

Edit 1: As, I said I have gone through the docs but I am not clear how to configure in this scenario. e.g. docs say

  1. In the source code on both computers, add the following lines, replacing my_secret with the appropriate passphrase to authenticate remote debugging, and replacing address with the appropriate IP address (or localhost) and port number:
ptvsd.enable_attach("my_secret", address = ('0.0.0.0', 3000))

But I have only one copy of source file i.e. on remote system. I have just mounted it on my local file system. So, should I give my local ip address or it should be remote system ip and which port number should I use as I am having only one copy of source and hence ptvsd, how is it going to communicate. Also, in the configuration, what should I use for localRoot location and remoteRoot location.

 3. {
     "name": "Attach (Remote Debug)",
     "type": "python",
     "request": "attach",
     "localRoot": "${workspaceFolder}",
     "remoteRoot": "${workspaceFolder}",
     "port": 3000,
     "secret": "my_secret",
     "host": "localhost" 
 }

Edit: Thanks to remote development extension in VSCode, remote debugging is super easy now.

1

1 Answer 1

2

You need to put the remote ip address in both ptvsd.enable_attach("my_secret", address = ('remote_ip_address', 3000)) and in launch.json:

{
  "name": "Attach (Remote Debug)",
  "type": "python",
  "request": "attach",
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "/home/user1/scripts/",
  "port": 3000,
  "secret": "my_secret",
  "host": "remote_ip_address" 
}

You also need to change the remoteRoot value to the path of the directory where the script is located in the remote machine (e.g. /home/user1/scripts/).

Finally, open an ssh connection: ssh -L 3000:localhost:3000, run your script in the remote machine and attach the debugger in the local machine.

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

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.