[Qgis-user] Python console sys.stdout.encoding

Adam Nielsen a.nielsen at shikadi.net
Wed Apr 10 01:07:32 PDT 2024


> Effectively it is part of the answer I am looking for.  But my problem is
> "higher" in the python settings for QGIS. If I write 'sys.stdout.encoding =
> "utf-8"' to the console, my plugin will be loaded without problem. I am
> developing a plugin whit "from ultralytics import YOLO" and I am receiving
> the following message :
> 
>            File
> "C:\Users\pierr\AppData\Roaming\Python\Python39\site-packages\ultralytics\ut
> ils\__init__.py", line 238, in set_logging
>              if WINDOWS and sys.stdout.encoding != "utf-8":
>             AttributeError: 'NoneType' object has no attribute 'encoding' 
> 
> Ultralytics YOLO needs an encoding attribute for "sys.stdout" to be
> imported. I didn't find any solution to set the encoding attribute with the
> startup.py file.

I'm no Python expert, but can you change that code so that it does not
rely on that property? e.g.

    if WINDOWS and hasattr(sys.stdout, 'encoding') and sys.stdout.encoding != "utf-8":

If that works maybe you can submit an upstream patch to the ultralytics
package?

Otherwise your only option would be to add the 'encoding' property to
the QGIS stdout redirection module as Andrea posted about earlier.

Cheers,
Adam.


More information about the QGIS-User mailing list