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:
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.
Python: Remote Attach. Make sure that launch.json has the host as the IP of your remote machine and port as 5678.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.
It is frustrating there are so many out-dated instructions how to remote debug Python scripts from VSC.
As of August 2024 there is a far easier way to set this up that answers the OP's question which involved VSC being installed on a laptop and debugging a Python script saved on a Raspberry Pi also in the same LAN.
Once you have installed the Remote SSH extension on your local machine use that to SSH via VSC in to your remote machine. Now install the Python Debugger extension on your remote system.
Since you have ssh'd in to that remote system via the VSC extension VSC just debugs the script on that remote system as though it is LOCAL.
You DO NOT need to...
I checked about what sockets were opened by separately ssh'ing from a Terminal in to the "remote system" (my Raspberry Pi running Ubuntu) and they are all localhost.
ubuntu@ubuntu:~$ lsof -i
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
code-f1e1 76603 ubuntu 9u IPv4 519530 0t0 TCP localhost:43675 (LISTEN)
code-f1e1 76603 ubuntu 12u IPv4 519534 0t0 TCP localhost:43675->localhost:34540 (ESTABLISHED)
python 77190 ubuntu 4u IPv4 520559 0t0 TCP localhost:39819 (LISTEN)
python 77190 ubuntu 8u IPv4 522535 0t0 TCP localhost:45381 (LISTEN)
python 77190 ubuntu 9u IPv4 521557 0t0 TCP localhost:45381->localhost:59082 (ESTABLISHED)
python 77190 ubuntu 11u IPv4 521558 0t0 TCP localhost:35979->localhost:37454 (ESTABLISHED)
python 77218 ubuntu 3u IPv4 520157 0t0 TCP localhost:37454->localhost:35979 (ESTABLISHED)
python 77228 ubuntu 3u IPv4 520164 0t0 TCP localhost:59082->localhost:45381 (ESTABLISHED)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With