Remote Debugging Python In Eclipse
Solution 1:
If you want to develop the code all remotely (instead of locally), my suggestion is using sshfs (so, you'd do all the changes there directly).
You should even be able to create a shell script to a remote interpreter in that case too (i.e.: the interpreter may be any script, so, you could chroot it or even run some python through ssh).
Note I haven't actually tested this, but in theory it should work ;)
Solution 2:
I found a way to get remote editing and remote debug going with eclipse and pydev from my mac to a Debian linux server (bitnami setup).
To set up remote editing and debugging - Read these first
https://www.pydev.org/manual_adv_remote_debugger.html https://sites.google.com/site/programmersnotebook/remote-development-of-python-scripts-on-raspberry-pi-with-eclipse
Notes on my install
- Installed pydevd in server python environment (did not need to copy pysrc as in raspy example above instructions). See links above for install steps.
- Created remote project using RSE. (Eclipse Remote Shell extensions) Using RSE "Remote shell" window you can right click on source directory and create a local Eclipse project that points at the server files. See links above for install steps.
- Edited
pydevd_file_utils.py
in server pydevd install directory. For me this was/opt/python/lib/python3.7/site-packages
. If you're not sure where this is enter the following in your server python environmentimport pydevd; print(pydevd.__file__)
. AddedPATHS_FROM_ECLIPSE_TO_PYTHON = [('/Users/<myusername>/dev/test/RemoteSystemsTempFiles/<server ref in RSE>/opt/bitnami/apps/odoo/data/addons/13.0/test/test.py','/opt/bitnami/apps/odoo/data/addons/13.0/test/test.py')]
. Read the comments and place it near the example lower down. - could add the following instead
PATHS_FROM_ECLIPSE_TO_PYTHON = [(r'/Users/andrewlemay/esp/test/RemoteSystemsTempFiles/34.253.144.28/',r'/')]
which means it would work for all RSE projects on the server. - Note the RemoteSystemTempFiles dir is part of Eclipse RSE path on your local machine
- Add SSH remote port forwarding tunnel. This forwards the data from the server on port 5678 to client localhost:5678 to allow the server remote debugger to send info to the listening client debugger - see command below. With this I did not need IP address in settrace() command or to configure my router to port forward to my local machine.
- INFO on SSH tunnels here https://www.ssh.com/ssh/tunneling/example
To run
- Set up secure SSH tunnel to server with remote port forwarding on 5678
- Run python script on server via console or RSE Remote Shell (Eclipse>Windowother>Remote systems>Remote Shell
Run commands
Client
I'm using a private shared key and I enter the following in a local terminal
ssh -t -i "/Users/<username>/keys/<serverkeyname>.pem" <serverusername>@<serverIP> -R 5678:localhost:5678 -C -N
The process will block the terminal. End process with CTRL-C when debugging done to close the tunnel. If you don't need a private shared key you can lose the -t -i "/Users/<username>/keys/<serverkeyname>.pem"
part.
Start Pydev server in eclipse by clicking the PyDev:start the pydev server
button (have to be in debug perspecive).
PyDev:start the pydev server
You should then get a message in Console saying Debug Server at port: 5678
Server
You can use server terminal or Eclipse RSE Remote Shell Window
Python3 test.py
The local Eclipse debug server should burst into life! and allow debugging and breakpoints etc.
Test code - test.py
import os
import sys
import pydevd
pydevd.settrace()
i = 3
p = 'Hello!' * i
print(p)
if __name__ == '__main__':
pass
print("Hello world 4")
for k, v in os.environ.items():
print(f'{k}={v}')
Hope this is useful to someone...
Post a Comment for "Remote Debugging Python In Eclipse"