Python報錯:none of the following families were found: SimHei

前提:python代碼執行報錯:

findfont: Generic family ‘sans-serif’ not found because none of the
following families were found: SimHei findfont: Generic family
‘sans-serif’ not found because none of the following families were
found: SimHei findfont: Generic family ‘sans-serif’ not found because
none of the following families were found: SimHei
/opt/module/python_shell/myoa/server.py:31: UserWarning: Glyph 20010
(\N{CJK UNIFIED IDEOGRAPH-4E2A}) missing from current font.
plt.savefig(save_path) /opt/module/python_shell/myoa/server.py:31:
UserWarning: Glyph 20154 (\N{CJK UNIFIED IDEOGRAPH-4EBA}) missing from
current font. plt.savefig(save_path)
/opt/module/python_shell/myoa/server.py:31: UserWarning: Glyph 20107
(\N{CJK UNIFIED IDEOGRAPH-4E8B}) missing from current font.
plt.savefig(save_path) /opt/module/python_shell/myoa/server.py:31:
UserWarning: Glyph 39033 (\N{CJK UNIFIED IDEOGRAPH-9879}) missing from
current font. plt.savefig(save_path) findfont: Generic family
‘sans-serif’ not found because none of the following families were
found: SimHei /opt/module/python_shell/myoa/server.py:31: UserWarning:
Glyph 20113 (\N{CJK UNIFIED IDEOGRAPH-4E91}) missing from current
font. plt.savefig(save_path)
/opt/module/python_shell/myoa/server.py:31: UserWarning: Glyph 26700
(\N{CJK UNIFIED IDEOGRAPH-684C}) missing from current font.
plt.savefig(save_path) /opt/module/python_shell/myoa/server.py:31:
UserWarning: Glyph 38754 (\N{CJK UNIFIED IDEOGRAPH-9762}) missing from
current font. plt.savefig(save_path)

疑問:本地的python是3.12版本,安裝了pip install matplotlib 之後,無沒有出現bug,但是把代碼打包到服務器上,報了錯誤,發現服務為的python版本是3.10版本

分析:
報這個錯誤,是因為少了 SimHei 字體
解決方案:
1.確定是否存在 SimHei 字體

import matplotlib
print(matplotlib.get_cachedir())

結果:
在这里插入图片描述
確定是少了SimHei字體
(2)官網下載SimHei:https://www.fontpalace.com/font-download/simhei/
建議去官網下載,比較安全
(3)將下載好的文件放到ttf路勁下,具體路徑是:/opt/module/miniconda3/lib/python3.10/site-packages/matplotlib/mpl-data/fonts/ttf
其中/opt/module/miniconda3/lib/python3.10是python安裝目錄
在这里插入图片描述
(4) 删除matplotlib的緩存字體
1.確定緩存路徑

import matplotlib
print(matplotlib.get_cachedir())

2.刪除輸出路徑的數據

5.修改matplotlibrc文件:路徑是:/opt/module/miniconda3/lib/python3.10/site-packages/matplotlib/mpl-data/matplotlibrc
修改內容如下:

# 去掉前面的#号
font.family:  sans-serif
# 去掉前面的#号,并在:号后面加上SimHei
font.sans-serif: SimHei, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
# 去掉前面的#号,并将True改为False
axes.unicode_minus: False

  • 17
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ysksolution

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值