0

Windows cmd does not handle utf8 well when executing print statements in python.
Many people said that we can type in "chcp 65001" before executing the python script in the cmd. In our situation, we want to implement an app (in python pyc) with a desktop icon in Windows.
Thus our first solution is adding os.system("chcp 65001") to the source python script before the main function.
But somehow this did not work. Then some people said trying os.system("/k chcp 65001").
But this did not work either.

Our second soluiton is using a bat file with two lines, the first line is "chcp 65001" while the second is "python my.pyc" where my.pyc is main program of our app. But this solution seems inconsistent since in some environment it failed while in others, it did not fail. Moreover, with this solution, Windows does not allow us to change the logo (or icon image) of bat file.

Can someone help us solve this problem with cmd and utf8 with python scripts?

tripleee
  • 175,061
  • 34
  • 275
  • 318
Farn Wang
  • 33
  • 5
  • i think this [answer](https://superuser.com/a/269857/1249511) would help – med benzekri Feb 26 '21 at 15:28
  • Maybe `sys.stdin.reconfigure(encoding='utf-8')`? – JosefZ Feb 26 '21 at 16:10
  • Sorry that I just found the user that reported this problem was using git bash instead of the windows cmd. So this problem should be solved in other ways. – Farn Wang Feb 27 '21 at 11:14
  • I just found some pages which might be more related to my problem. Here is such a page. Thanks https://stackoverflow.com/questions/45660817/python-print-unicode-string-via-git-bash-gets-unicodeencodeerror – Farn Wang Feb 27 '21 at 14:19

0 Answers0