The terminal operation of Pycharm and pycharm is inconsistent with the operation of CMD, and there is a problem of converting Chinese to English (or English to Chinese)

The terminal operation of Pycharm and pycharm is inconsistent with the operation of CMD, and there is a problem of converting Chinese to English (or English to Chinese)

1. Problem description

​ My colleague sent me a tool for me to package, saying that the local pycharm runs perfectly when debugging, but after packaging with pyinstaller, the exe will report an error after running in cmd, and the debug found in pycharm and pycharm's terminal operation output results Chinese is changed to English after the exe runs on cmd, which leads to a series of bugs. For example, "username" in Chinese is displayed as "User Name" in CMD, which causes problems when split cuts spaces.
insert image description here

Two, the solution

​ At first I thought it was a packaging problem, but later I found that running the py file directly in cmd also had the same problem. After excluding the problem of pyinstaller, I thought it was a problem with the source code, and then I started to unlock the exception capture and start changing the source code and directly copying the source code All the Chinese in the file were replaced with English. After changing it, it was found that the output information in the picture was all received parameters, so the problem was not in the encoding of the source code. Then I suspect the operating system and cmd. All kinds of trial and error in the virtual machine are the same problem. After eliminating the problem of the operating system, cmd is left. Baidu, just change the encoding method of cmd. , perfect solution.

​ Solution:

​ cmd command line input: chcp code number

​My problem is to transfer to GBK and enter chcp 936 to run py or exe perfectly

You can run py or exe perfectly
insert image description here

Guess you like

Origin blog.csdn.net/L_W_D_/article/details/113662720