Skip to content Skip to sidebar Skip to footer

Launch Console Window Pre-activated With Chcp 65001 Using Python

I use a python library that prints out a Unicode character to windows console. If I call a function on the library that prints out Unicode character, it will throw an exception 'ch

Solution 1:

Add /k chcp 65001 to the shortcut launching the cmd window. Alternatively, use Python 3.6 which uses Windows Unicode APIs to write to the console and ignores the code page. You do still need font support for what you are printing, however.


Solution 2:

Next settings works on Windows 8.1:

==> set "PYTHONIOENCODING=UTF-8"

==> chcp 65001
Active code page: 65001

==> type "%APPDATA%\Python\Python35\site-packages\usercustomize.py"
import win_unicode_console
win_unicode_console.enable()

Test:

==> python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> print (u'ěščřžýáíé ;ςερτυ яшертю ğüşi')
ěščřžýáíé ;ςερτυ яшертю ğüşi
>>>

Strings in test (senseless, just for demonstration):

  • ěščřžýáíé Latin, Central European
  • ;ςερτυ    Greek
  • яшертю    Cyrillic
  • ğüşi      Latin, Turkish

Post a Comment for "Launch Console Window Pre-activated With Chcp 65001 Using Python"