1. Download the SimHei font and put it in ttf (the location is from bottom to top, data mining is my project name):
Font download address (click directly to download, the link is not my original one):
https://us-logger1.oss-cn-beijing.aliyuncs.com/SimHei.ttf
2. Run this code in the python project:
import matplotlib
matplotlib.get_cachedir()
Get an address, copy this address, and then in the project terminal
run:
rm -rf 该地址
The running result is as shown in the figure:
This step means to delete the buffer directory of matplotlib.
3. I found that I don’t need to do the following step !
4. The above step is a step that I saw many people take when dealing with the problem, but I found that if I modified it like that, my code would report an error when running! The error is reported as shown in the figure:
Error:Cannot run program "/Users/mac/PycharmProjects/sjwjProject2/venv/bin/python" (in directory "/Users/mac/PycharmProjects/sjwjProject2"): error=2, No such file or directory
But I don’t know if you need that step, so I’ll put it here. If you follow the second step as I said, run your project. If the font still doesn’t take effect, continue to the third step!
I wish you success!