pycharm terminal command line Chinese garbled solution

ssh to connect to the server, run the script and find Chinese garbled characters displayed on the terminal. Baidu has tried many methods, but they have not solved it. Later, I changed a putty connection to run it, and the Chinese on the output screen was not garbled. It can be determined that it is a pycharm setting problem.

 Setting method: File -- settingings -- Tools -- SSH Terminal -- Default encoding is set to UTF-8.

Because the script we wrote is utf8 encoded. The terminal should also be set to recognize utf8 encoding.

The way to declare that the script is utf8:  

#  -*- coding: UTF-8 -*
#!/usr/bin/python
#  -*- coding: UTF-8 -*
f = open('test.py', 'r')

print('Chinese')

  

To sum up, you need to use Chinese normally:

1. Save the file as utf8 encoding. The editor opens the file, and you can see the encoding of the current file in the lower right corner.

2, the script opens the declaration utf8

3. Terminal set utf8

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324774698&siteId=291194637