linux: 安装字体:黑体

一,linux的字体安装在哪里?

查看字体目录:

$ fc-list
/usr/share/fonts/google-droid/DroidSansHebrew-Regular.ttf: Droid Sans:style=Regular
/usr/share/fonts/urw-base35/NimbusMonoPS-Italic.otf: Nimbus Mono PS:style=Italic
/usr/share/fonts/urw-base35/D050000L.t1: D050000L:style=Regular
/usr/share/fonts/urw-base35/NimbusSansNarrow-Regular.t1: Nimbus Sans Narrow:style=Regular
/usr/share/fonts/urw-base35/NimbusSansNarrow-BoldOblique.t1: Nimbus Sans Narrow:style=Bold Oblique
/usr/share/fonts/simhei/simhei.ttf: SimHei,黑体:style=Regular
/usr/share/fonts/urw-base35/NimbusMonoPS-Bold.otf: Nimbus Mono PS:style=Bold
/usr/share/fonts/urw-base35/P052-Roman.otf: P052:style=Roman
/usr/share/fonts/simsun/simsun.ttc: NSimSun,新宋体:style=Regular
/usr/share/fonts/urw-base35/P052-Italic.t1: P052:style=Italic
/usr/share/fonts/google-droid/DroidSansArabic.ttf: Droid Sans:style=Regular
/usr/share/fonts/dejavu/DejaVuSansCondensed-Oblique.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
/usr/share/fonts/google-droid/DroidSansEthiopic-Regular.ttf: Droid Sans:style=Regular
/usr/share/fonts/urw-base35/C059-BdIta.otf: C059:style=Bold Italic
/usr/share/fonts/dejavu/DejaVuSansCondensed-Bold.ttf: DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold
/usr/share/fonts/urw-base35/StandardSymbolsPS.t1: Standard Symbols PS:style=Regular
/usr/share/fonts/urw-base35/URWBookman-DemiItalic.t1: URW Bookman:style=Demi Italic
/usr/share/fonts/google-droid/DroidSansFallback.ttf: Droid Sans:style=Regular
/usr/share/X11/fonts/Type1/c0611bt_.pfb: Courier 10 Pitch:style=Bold Italic
/usr/share/fonts/urw-base35/C059-Roman.t1: C059:style=Roman
/usr/share/fonts/urw-base35/NimbusRoman-Italic.t1: Nimbus Roman:style=Italic
/usr/share/fonts/urw-base35/C059-BdIta.t1: C059:style=Bold Italic
/usr/share/fonts/urw-base35/URWBookman-LightItalic.otf: URW Bookman:style=Light Italic
/usr/share/fonts/urw-base35/URWGothic-DemiOblique.otf: URW Gothic:style=Demi Oblique
/usr/share/X11/fonts/Type1/UTBI____.pfa: Utopia:style=Bold Italic
/usr/share/fonts/urw-base35/NimbusSansNarrow-BoldOblique.otf: Nimbus Sans Narrow:style=Bold Oblique
/usr/share/fonts/google-droid/DroidSansTamil-Regular.ttf: Droid Sans:style=Regular
/usr/share/fonts/urw-base35/NimbusSans-Bold.otf: Nimbus Sans:style=Bold
/usr/share/fonts/urw-base35/NimbusRoman-Bold.otf: Nimbus Roman:style=Bold
/usr/share/fonts/urw-base35/D050000L.otf: D050000L:style=Regular
/usr/share/X11/fonts/Type1/c0419bt_.pfb: Courier 10 Pitch:style=Regular
/usr/share/fonts/dejavu/DejaVuSans.ttf: DejaVu Sans:style=Book 

可以看到主要安装在 /usr/share/fonts和/usr/share/X11/fonts目录下

二,新增字体:

复制文件到相应的目录下

$ sudo cp -axv simhei/ /usr/share/fonts/truetype/
[sudo] password for liuhongdi: 
'simhei/' -> '/usr/share/fonts/truetype/simhei'
'simhei/.uuid' -> '/usr/share/fonts/truetype/simhei/.uuid'
'simhei/simhei.ttf' -> '/usr/share/fonts/truetype/simhei/simhei.ttf'

然后就可以看到字体文件了:

$ fc-list | grep hei
/usr/share/fonts/truetype/wqy/wqy-microhei.ttc: 文泉驿微米黑,WenQuanYi Micro Hei,文泉驛微米黑:style=Regular
/usr/share/fonts/truetype/simhei/simhei.ttf: 黑体,SimHei:style=Regular
/usr/share/fonts/truetype/wqy/wqy-microhei.ttc: 文泉驿等宽微米黑,WenQuanYi Micro Hei Mono,文泉驛等寬微米黑:style=Regular

三,安装后无效?

4刷新 Matplotlib 缓存

有时候安装了字体但 Matplotlib 仍然报错,是因为它读取了旧的缓存。

请执行:

rm -rf ~/.cache/matplotlib


然后重新运行 Python 脚本

posted @ 2026-05-09 17:18  刘宏缔的架构森林  阅读(6)  评论(0)    收藏  举报