Closed
Description
Describe the bug
I'm trying to do a print statement on Windows environment using rich
and I get an exception.
rich.print("[bright_blue uu]" + message)
Provide a minimal code example that demonstrates the issue if you can. If the issue is visual in nature, consider posting a screenshot.
Windows 10 x64
Faust streaming application.
I'm using the terminal emulated by PyCharm.
From what I can tell the error is in console.py, around here:
try:
use_legacy_windows_render = (
self.file.fileno() in _STD_STREAMS_OUTPUT
)
except (ValueError, io.UnsupportedOperation):
pass
The error doesn't appear in the main application, it appears in a library that uses rich
.
If I write the same console message from my main application, before the library does it then it works ok.
But if the library wants to write the message it fails with the exception mentioned above.
Activity
eblis commentedon Nov 15, 2022
I think the code should also ignore NotImplementedError as well:
Changing the
console.py
code to this allows the messages to be written to console.willmcgugan commentedon Nov 15, 2022
That would certainly fix it, although
fileno
should not raise aNotImplementedError
. You might want to raise this with the library that is supplying the file-like object.eblis commentedon Nov 15, 2022
In my main application the

self.file
member is initialized to this:But later, in my library, it's (re?)initialized to this:

I didn't initialize it to this value, it was probably Faust (or I don't know who) who modified the file object.
I'm initializing a rich console like this:
And then writing the message like so:
Edit: I thought I had sent this with the other replies a while back, but looks like it was a draft, I sent it now just so we have all the details.
github-actions commentedon Nov 30, 2022
I hope we solved your problem.
If you like using Rich, you might also enjoy Textual