0

I'm trying to output unicode symbols from Python 3. The program is a simple one-liner where I'm printing non-ascii literals:

print("íó")

The program is encoded in utf-8.

I'm running this program on two different Windows machines (Windows 7, Windows 10); on each machine I'm running this from both cmd and MinGW.

That works on Windows 10 (both cmd and MinGW).

On Windows 7 the output is decayed to ascii if run from cmd, and Python throws an exception if being run from MinGW:

Traceback (most recent call last): File "test.py", line 4, in print("\xed\xf3") File "C:\Program Files (x86)\Python36-32\lib\encodings\cp1251.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-1: character maps to

What could be the problem? What should be the difference in the machines (the Python and MinGW versions are very close)? What is the difference of Python run from cmd and MinGW that cause the exception?

Machines configurations:

  • Windows 7; Python 3.6.0; MinGW 2.8.3
  • Windows 10; Python 3.6.5; MinGW 2.8.5
Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40
  • For `sys.stdin` and `sys.stdout` (the latter of which is used by `print()`), Python uses a locale-dependent encoding default. Depending on the terminal/IDE you use to run Python, you might or might not be able to get full Unicode support. From SO's "Related" suggestions, I quickly looked at [this thread](https://stackoverflow.com/q/507123), which is a *little bit* old, but it might well apply to the Windows-7 problem. – lenz Oct 12 '19 at 08:01
  • in MinGW (and in all unix like systems): get `locale -a` and select a locale with UTF-8: e.g. `export LANG=en_US.utf8` (warning: check with locale -a that this locale exists, on other systems/versions that locale could have different spelling) – Giacomo Catenazzi Oct 14 '19 at 07:58

0 Answers0