How to debug remote Python script in VS Code - python-3.x

I am doing Python development in Raspberry Pi. I have installed VS Code in my laptop and have installed the ssh extension. Using this I can easily connect to Raspberry Pi. While I am connected I can see that VS Code has also loaded the Python interpreter of Raspberry Pi. I can run my Python script from within the vs code but when I tried to debug the code, nothing happens.
Is it possible to remotely debug the Python script from laptop to Raspberry Pi? How can I enable this?

I have resolved this issue. If anyone wants to do remote development and debugging, follow below steps:
Install remote ssh extension in VS code
Once installed, you will find a green icon on the bottom left corner in vs code which allows us to connect to the remote machine.
Connect to the remote machine using the standard ssh command. Alternatively, you can use ssh-keygen to generate a public-private key if you don't want to use the password at every prompt.
Once you are connected to remote machine, you can open the file explorer and create any python file. When you will save this, it will get saved in your remote machine. This way you are using your machine to remotely develop code on another remote machine.
Good thing about vs code is that it selects the remote machine's python interpreter so all the packages which you have installed on your remote machine will work with IntelliSense.
In order to debug the code, we will use debugpy. Install this on both machine (remote & local)
On your remote machine, run below command:
python3 -m debugpy --listen 1.2.3.4:5678 --wait-for-client app.py
here 1.2.3.4 is the IP of remote machine. This will start a remote debugger which will wait for a clients connection.
On your local machine, in VS code open Run & Debug, add a configuration of Python: Remote Attach. Make sure that launch.json has the host as the IP of your remote machine and port as 5678.
Now start debugging as normal and you will notice the code will break at first breakpoint and from here you can proceed normally as we used to do in local debugging process.
TBH, this is best feature VS code has because most of the software allows you to do remote development which is nothing but just a normal SSH but remote debugging gives you more control. I was doing some python project on Raspberry Pi and obviously cannot install VS code or pycharm on it. But with this feature now I can easily develop the code using Pi's python interpreter and debug it as well.
If anyone is having any issues, let me know. Happy to help.

Related

Eclipse unable to connect to remote Linux via SSH

I am trying to set-up Eclipse on Windows to build and debug a C application on an i.MX6 eval kit running Yocto Linux. When I try to connect either via the debugger or via the Remote System Explorer I get the following error:
Could not open connection.
Reason: Algorithm Negotiation fail
I can connect to the board via Tera Term using SSH and port 22, so it seems like GDB server is running, but there is some incompatibility between Eclipse SSH and Linux SSH. I've seen several posts about this, but most of them are years old, and no longer apply. I tried changing the connection settings in Eclipse, but nothing I have tried seems to work.
How do I configure Eclipse, or Yocto Linux, to allow them to communicate?

Open VSCode from Remotly Server to Local like WSL2

Recently i created one server (with centos) on another computer, i assigned static local ip (192.168.1.100) and i my computer has local static ip too (192.168.1.50), and i would like open the vscode from my local computer when i run "code" command on remote server (like code .) inside vscode of my computer.
Basically like WSL2 works, but, when we install the distro of WSL2, the vscode install automatically one extension for WSL2, and that works.
And another question, is about the terminal of local vscode, when i open the vscode terminal, i would like to open the remote server terminal (ssh) on the current folder. (Exactly like WSL2)
Basically i would like create a WSL2 outside from the same computer. The "SubSystem" i want to install are on another computer (my server)
I think that's what you're looking for 1
A simpler method would be to install ssh-remote plugin in VSCode and you will see Remote Explorer in your left bar. After you log in once to that server you will see the connection and with a simple click, you can connect from there.

VSCode execute node script on remote linux or windows machine

Using VSCode, is it possible to execute a node.js script on a remote linux or windows system without setting up a full Visual Studio Code Remote Development Environment?
Assume the following:
VSCode installed on client (Windows)
remote system is a virtual machine running on the client. It has access to the project folder (including the script to be executed and the node modules) on the client. Node is installed on the remote system.
Actually I just need something like a launch configuration which executes an SSH command for linux, for windows maybe something else. With these assumptions (shared project folder between remote system and client), is that possible without setting up a full Visual Studio Code Remote Development Environment? I don't need remote editing or debugging.

Remote System Development Eclipse - Build, Debug and Run from remote Linux machine

I have the following:
1) Windows machine with Eclipse CDT (Currently Luna v4.4.1)
2) A Linux machine that has the repository with code and the Linux GCC, make etc..
I want to connect to the Linux via Remote System Explorer in Eclipse, edit, build, debug and run all from the Windows machine in Eclipse.
I have been successful in setting up the SSH connection and in the project explorer, I can access the remote repository and edit the code.
The issue I am having is building, debugging and running it.
How can I let eclipse know I want to compile it remotely? The Project -> Build functionality is blocked out when attempting for the remote repository. It only allows it for local repo's. But I already have an SSH connection.. Is there not a way for it to know that I want to use the remote GCC too?
Also, for debugging, in the Debug configuration it seems to want a local version of the build, even though I selected remote debugging.
Sorry I don't have any error logging to report as i'm just struggling on the first bit of how I go about doing the remote build in the IDE.
Maybe this is not possible?

SSH into raspberry pi

I have a question regarding SSH. For school assignments, I always write code on my mac then transfer it over on my raspberry pi to make sure it will compile correctly without errors as they are tested on the pi and sometimes when I transfer it has errors.
To avoid hassle of connecting everything to the pi, if I SSH into the pi, then compile my program from my mac, would it use the raspberry pi compiler?
If you are connected vi ssh and issuing the commands in that terminal session, yes, it's going to use the compiler on the pi.
A better option, and more educational, might be to cross-compile the code for the pi on your mac. You can leverage the much greater processing power of the desktop to significantly reduce your compile time.
Cross Compiling on Mac OSX for Raspberry Pi
Yes it would remotely access the host's OS (in your case the RPi) to perform the compilation.
Here is a guide to get you started:
https://www.modmypi.com/blog/remotely-accessing-the-raspberry-pi-via-ssh-console-mode
Also, in case you want a remote desktop connection, on your raspberry pi enter the following command:
sudo apt-get install xrdp
providing you've already updated and upgraded your package libraries ;)
Yes, If you are using ssh and writing code in that terminal session then the code will be compiled in the pi, it is the best way to do so.
Issuing command in the terminal session via SSH (laptop connected with Raspi), compilation will be done at Raspi. PuTTY is a very useful tool for this, you just need to enable SSH at Raspi and input your IP address at PuTTY only! Click to the PuTTY website http://www.putty.org/ and download it.
Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. The best-known example application is for remote login to computer systems by users.
When you connect to any remote system or server via ssh you are using the same system via command prompt. So, if you do any work via SSH the compilation will be done by the remote system.

Resources