python config_error ai_generated true

findfont: Font family 'Arial' not found.

ID: python/matplotlib-findfont-cache-stale

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
0Evidence
2024-08-11First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active — — —

Root Cause

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

generic

中文

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

Workarounds

  1. 90% success
    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% success
    import matplotlib.pyplot as plt
    plt.rcParams['font.family'] = 'DejaVu Sans'  # shipped with matplotlib

Dead Ends

Common approaches that don't work:

  1. 93% fail

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

  2. 88% fail

    Upgrading matplotlib does not install OS-level font packages.