Linux Chinese garbled code problem

Time:2021-8-27

Linux version

  • Ubuntu 16.04

Problem description

  • The Linux command line displays garbled code in Chinese, as shown in the following figure:

Linux Chinese garbled code problem

  • Run Python code program on Linux platform. When you encounter coding problems in reading and writing Chinese files (you can try to check the system coding)

Solution

  • Open. Bashrc in the home directory (this file is generally used to configure personal settings)
[email protected]:~$ vi ~/.bashrc
  • Add at the bottom of the document:
#Lang - defines the subject variables of the system
# en_ Us.utf-8: you speak English. You are in the United States. The character set is UTF-8. The default language of the system menu, program toolbar language and input method is English
LANG=en_US.UTF-8
# LANG=zh_ Cn.utf8: you speak Chinese. You are in China. The character set is UTF-8. The default language of the system menu, program toolbar language and input method is Chinese
LANG=zh_CN.utf8
  • Execute the file
[email protected]:~$ source ~/.bashrc