Eli Weinstock-Herman

Python 3.5+: Unicode output for Windows Console

Original post posted on November 20, 2016 at LessThanDot.com

I’ve tripped over this on 2 machines now and end up at the same out of date StackOverflow post, so maybe this will help someone else.

Python 3.5, not 3.6, I had that wrong initially 🙂

Situation
When you try to print a string with a Unicode character to the console on Windows in Python, you get:
UnicodeEncodeError: 'charmap' codec can't encode characters in position 20-21: character maps to <undefined>

Looking something like this:

Python UnicodeEncodeError

Python UnicodeEncodeError

Fix
Windows command-line supports unicode now, and Python 3.6+ ties into this support automatically (prior version requires win-unicode-console). You just need a slight bit of magic dust.

Add an environment variable named PYTHONIOENCODING to your environment settings, like so:

PYTHONIOENCODING Environment Variable

PYTHONIOENCODING Environment Variable

And now when you execute, you get console output instead of an error:

Python Console Output without Unicode Error

Python Console Output without Unicode Error

Comments are available on the original post at lessthandot.com