Remote Debugging on Raspberry PI via SSH

1,039 views
Skip to first unread message

ergo

unread,
May 9, 2021, 6:45:21 AM5/9/21
to thonny
Hi Aivar,

i like Thonny a lot so far, thanks for making it available and your eager maintenance!

I am currently trying to run and debug a script running on the raspi connected via ssh. The debug function is not available using the remote python interpreter. Which plugin has to be installed or configuration made to make this possible?

Thanks, 
ergo

Aivar Annamaa

unread,
May 9, 2021, 8:56:02 AM5/9/21
to thonny
Hi!

Debugging over SSH is not available at the moment. The code actually supports debugging remote scripts, but remote debugging of local scripts doesn't work yet, so the feature is disabled. You can enable by modifying source code (select "Tools => Open Thonny program folder" and apply this change: https://github.com/thonny/thonny/commit/1f009d53c518dd20833dc866362bc733ec153128).

Best regards,
Aivar

ergo

unread,
May 9, 2021, 3:40:47 PM5/9/21
to thonny
Thanks for your quick answer!

My Python-Script is on the RasPi, Thonny is on my Mac, i am connected via ssh (Run > Select interpreter > Remote Python 3 (SSH)): That sounds like the case of "debugging remote scripts", right?

I added the two lines as provided here https://github.com/thonny/thonny/commit/1f009d53c518dd20833dc866362bc733ec153128 but got the following error:

WARNING thonny.common: Could not get THONNY_FRONTEND_SYS_PATH
Traceback (most recent call last):
  File "/tmp/thonny-backend-3.3.6/thonny/common.py", line 660, in try_load_modules_with_frontend_sys_path
    frontend_sys_path = ast.literal_eval(os.environ["THONNY_FRONTEND_SYS_PATH"])
  File "/usr/lib/python3.7/os.py", line 678, in __getitem__
    raise KeyError(key) from None
KeyError: 'THONNY_FRONTEND_SYS_PATH'
ERROR   thonny.backend: PROBLEM WITH THONNY'S BACK-END
Traceback (most recent call last):
  File "/tmp/thonny-backend-3.3.6/thonny/plugins/cpython/cpython_backend.py", line 1278, in execute_source
    root = self._prepare_ast(source, filename, mode)
  File "/tmp/thonny-backend-3.3.6/thonny/plugins/cpython/cpython_backend.py", line 1736, in _prepare_ast
    ast_utils.mark_text_ranges(root, source)
  File "/tmp/thonny-backend-3.3.6/thonny/ast_utils.py", line 178, in mark_text_ranges
    from asttokens.asttokens import ASTTokens
ModuleNotFoundError: No module named 'asttokens'

I checked installed plugins and asttokens is installed in version 2.0.4.
Any idea how to fix this? 

Thank you for helping here!

Aivar Annamaa

unread,
May 9, 2021, 4:49:22 PM5/9/21
to thonny
Try installing asttokens for your remote interpreter (ie. on Raspberry). If you're using your system Python 3 then you should do "sudo apt install python3-asttokens", if you're using a virtual environment, then "pip install asttokens". You may need to add also jedi ("sudo apt install python3-jedi" or "pip install jedi")

Best regards,
Aivar

ergo

unread,
May 10, 2021, 3:15:04 AM5/10/21
to thonny
Guess we are getting closer...

I installed both (asttokens and jedi) on the raspi and this is what i get from Thonny now:

Traceback (most recent call last):
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/workbench.py", line 1708, in event_generate
    handler(event)
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/plugins/debugger.py", line 1213, in _handle_debugger_progress
    _current_debugger.handle_debugger_progress(msg)
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/plugins/debugger.py", line 276, in handle_debugger_progress
    self._main_frame_visualizer = EditorVisualizer(msg.stack[0])
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/plugins/debugger.py", line 584, in __init__
    get_workbench().get_editor_notebook().show_file(frame_info.filename, set_focus=False)
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/editors.py", line 923, in show_file
    editor = self.get_editor(filename, True)
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/editors.py", line 1012, in get_editor
    return self._open_file(filename)
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/editors.py", line 996, in _open_file
    if editor._load_file(filename):
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/editors.py", line 171, in _load_file
    result = self._load_local_file(filename, keep_undo)
  File "/Applications/Thonny.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/thonny/editors.py", line 193, in _load_local_file
    with open(filename, "rb") as fp:
FileNotFoundError: [Errno 2] No such file or directory: '/home/pi/python-projects/smart-timer.py'


Aivar Annamaa

unread,
May 10, 2021, 4:08:23 AM5/10/21
to thonny
Ouch, it looks like we need to stop here for now. When I said the code is ready for debugging remote scripts, I had tried only a single trivial script, but from your stacktrace I infer that you have several scripts in your solution and it looks like the UI part of the debugger is not there yet. 

I'll try to make it working by Thonny 4.0. You can subscribe to https://github.com/thonny/thonny/issues/1814 to get notified of the progress.

Best regards,
Aivar

ergo

unread,
May 10, 2021, 4:24:00 AM5/10/21
to thonny
Ok, thanks for your efforts. Looking forward to v4 !

ergo

unread,
May 17, 2021, 3:00:11 AM5/17/21
to thonny
Aivar, one more question related to debugging a script remotely: Is it possible to debug my script (on the raspi) running Thonny on my Mac while the raspi is connected via USB? I saw no interpreter option to choose a usb-connection...

Aivar Annamaa

unread,
May 17, 2021, 3:18:41 AM5/17/21
to thonny
I haven't tried it, but it should be possible to create SSH connection over USB. See https://howchoo.com/pi/raspberry-pi-gadget-mode or ask in Raspberry's forum.

Best regards,
Aivar
Reply all
Reply to author
Forward
0 new messages