python config_error ai_generated true

findfont: 未找到字体族 'Arial'。

findfont: Font family 'Arial' not found.

ID: python/matplotlib-findfont-cache-stale

其他格式: JSON · Markdown 中文 · English
80%修复率
87%置信度
0证据数
2024-08-11首次发现

版本兼容性

版本状态引入弃用备注
3.x active — — —

根因分析

请求的字体未安装在系统上,或安装新字体后 matplotlib 的字体缓存已过期。

English

The requested font is not installed on the system, or matplotlib's font cache is stale after installing a new font.

generic

解决方案

  1. 90% 成功率
    sudo apt-get install -y fonts-liberation
    rm -rf ~/.cache/matplotlib
    python -c "import matplotlib.font_manager as fm; fm._load_fontmanager(try_read_cache=False)"
  2. 95% 成功率
    import matplotlib.pyplot as plt
    plt.rcParams['font.family'] = 'DejaVu Sans'  # shipped with matplotlib

无效尝试

常见但无效的做法:

  1. 93% 失败

    The font file is genuinely absent; naming it does not create it.

  2. 88% 失败

    Upgrading matplotlib does not install OS-level font packages.