Plug-in cannot import stackprinter on Windows

瀏覽次數:34 次
跳到第一則未讀訊息

tabreturn

未讀,
2022年7月8日 清晨6:58:362022/7/8
收件者: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

未讀,
2022年7月8日 中午12:44:152022/7/8
收件者: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

未讀,
2022年7月8日 下午5:23:382022/7/8
收件者: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

未讀,
2022年7月13日 晚上9:38:252022/7/13
收件者: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

未讀,
2022年7月15日 凌晨2:31:442022/7/15
收件者: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

未讀,
2022年7月25日 晚上7:06:182022/7/25
收件者:thonny
Thanks, Aivar!
回覆所有人
回覆作者
轉寄
0 則新訊息