What about the garbled codes in linux python?
This article will explain in detail about linux python Chinese garbled how to do, Xiaobian think quite practical, so share to you as a reference, I hope you can read this article after harvest.
Linux python Chinese garbled solution: 1. View matplotlib font location;2. Upload font to server;3. Delete font cache;4. Restart python application.
Operating environment: linux 5.9.8 system, Anaconda3, Dell G3 computer.
Python Chinese garbled code solution under linux
1. scene description
Linux server installed Anaconda3, Pyhton's K-means algorithm, the result appears as follows: Chinese characters garbled. The last time has been solved, forgot to record the solution process, this time configured a new server, appeared again, the default is not configured, matplotlib will draw garbled code, this time the solution process recorded, hope to help themselves and friends in need.
2. solutions
There are several solutions online, only to introduce their own practical feasible.
1. View matplotlib font location
pythonimport matplotlib print(matplotlib.matplotlib_fname())#Write it down, the font position is: /home/ruanjianlaowang/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrcexit()
2. Upload fonts to server
cd /home/ruanjianlaowang/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-data/fonts/ttf Transfer fonts via ftp or other means, we pass: simhei.ttf
3. Delete font cache
cd ~/.cache/matplotlibrm -rf *
4. Restart Python applications
nohup python k-means.py &
Note: If it hasn't yet taken effect, try changing a configuration file. (We haven't changed this configuration file before, but this time there was an episode, this time with jmeter test, has been garbled, later changed this or not, the original is jmeter problem)
cd /home/ruanjianlaowang/anaconda3/lib/python3.7/site-packages/matplotlib/mpl-datavi matplotlibrc font.family : sans-serif #Remove the previous #font.serif : simhei, DejaVu Serif, #Added simhei
episode
This time with jmeter test, found that all changed or garbled, and later jmeter request added utf-8 parameter can be.
About "linux python Chinese garbled how to do" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.