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?
2
Answers
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 thatlaunch.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.
To highly simplify the remote debugging process between two windows machines, make is universal for all IDEs and avoid SSH file permission errors on Windows, I made my own python library that solves this problem.
Just run
pip install pywinrd
and create those two scripts:-Server.py
Client.py
Run
Server.py
on the host Windows machine, andClient.py
on your machine, you will have the ability to execute terminal commands, deploy extra files/folders and debug any python script you want on the host machine.A copy of all the stdout, stderr calls on the python script you are debugging will be redirected to your machine in real-time (ex. print and raise statements).
All the stdin calls will be redirected to your machine only (ex. input statements), so the server will not interfere with them.