diff --git a/poetry/console/application.py b/poetry/console/application.py index 6adda8609ef..222094d9643 100644 --- a/poetry/console/application.py +++ b/poetry/console/application.py @@ -21,6 +21,7 @@ from cleo.io.outputs.output import Output from poetry.__version__ import __version__ +from poetry.core.utils._compat import PY37 from .command_loader import CommandLoader from .commands.command import Command @@ -143,6 +144,20 @@ def create_io( ) -> IO: io = super().create_io(input, output, error_output) + # Remove when support for Python 3.6 is removed + # https://github.com/python-poetry/poetry/issues/3412 + if ( + not PY37 + and hasattr(io.output, "_stream") + and hasattr(io.output._stream, "buffer") + and io.output._stream.encoding != "utf-8" + ): + import io as io_ + + io.output._stream = io_.TextIOWrapper( + io.output._stream.buffer, encoding="utf-8" + ) + # Set our own CLI styles formatter = io.output.formatter formatter.set_style("c1", Style("cyan"))