Plug-in cannot import stackprinter on Windows

45 views
Skip to first unread message

tabreturn

unread,
Jul 8, 2022, 6:58:36 AM7/8/22
to thonny
My thonny-py5mode plug-in works fine on macOS and Linux, but fails on Windows. It seems there's an issue importing stackprinter (on Windows only).

...
File "C:\Users\USER\Desktop\thonny-4.0.0b3-windows-portable\user_data\plugins\Python310\site-packages\stackprinter\tracing.py", line 53, in <module> class TracePrinter():
File "C:\Users\USER\Desktop\thonny-4.0.0b3-windows-portable\user_data\plugins\Python310\site-packages\stackprinter\tracing.py", line 82, in TracePrinter print_function=sys.stderr.write,
AttributeError: 'NoneType' object has no attribute 'write'
...

Any ideas how I might fix this?
Thanks in advance. T

Aivar Annamaa

unread,
Jul 8, 2022, 12:44:15 PM7/8/22
to thonny
Where do you invoke stackprinter -- in Thonny's GUI process or in the backend process?

Can you show your module where stackprinter is being used?

Best regards,
Aivar

tabreturn

unread,
Jul 8, 2022, 5:23:38 PM7/8/22
to thonny
It's imported in my plug-in __init__ file, via importing py5_tools --

https://github.com/tabreturn/thonny-py5mode/blob/main/thonnycontrib/thonny-py5mode/__init__.py

T

tabreturn

unread,
Jul 13, 2022, 9:38:25 PM7/13/22
to thonny

Sorry -- I've since removed the problematic code as a workaround. Here's a version that runs into a stackprinter issue --
https://github.com/tabreturn/thonny-py5mode/blob/stackprinter-version/thonnycontrib/thonny-py5mode/__init__.py

On line 11, there's an import py5_tools. It's py5_tools that leverages stackprinter. As I explained originally, this works fine on macOS and Linux, but fails on Windows.

Any ideas?

Thanks
T

Aivar Annamaa

unread,
Jul 15, 2022, 2:31:44 AM7/15/22
to thonny
I now investigated stackprinter code, found the reason and described it at https://github.com/cknd/stackprinter/issues/55

If stackprinter doesn't publish a fix soon enough, you could try a work-around by assigning a mock object with `write` attribute to `sys.stderr` if it happens to be None. This should be done before importing stackprinter the first time.

Best regards,
Aivar 

tabreturn

unread,
Jul 25, 2022, 7:06:18 PM7/25/22
to thonny
Thanks, Aivar!
Reply all
Reply to author
Forward
0 new messages