{"record":{"id":"2397abdcca6fa0a8","repo":"matplotlib/matplotlib","slug":"failed-to-find-any-font-and-fallback-to-the-defau","errorCode":null,"errorMessage":"Failed to find any font, and fallback to the default font was disabled","messagePattern":"Failed to find any font, and fallback to the default font was disabled","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/matplotlib/font_manager.py","lineNumber":1572,"sourceCode":"                else:\n                    _log.warning(\"findfont: Font family %r not found.\", family)\n\n        # only add default family if no other font was found and\n        # fallback_to_default is enabled\n        if not fpaths:\n            if fallback_to_default:\n                dfamily = self.defaultFamily[fontext]\n                cprop = prop.copy()\n                cprop.set_family(dfamily)\n                fpaths.append(\n                    self.findfont(\n                        cprop, fontext, directory,\n                        fallback_to_default=True,\n                        rebuild_if_missing=rebuild_if_missing,\n                    )\n                )\n            else:\n                raise ValueError(\"Failed to find any font, and fallback \"\n                                 \"to the default font was disabled\")\n\n        return fpaths\n\n    @lru_cache(1024)\n    def _findfont_cached(self, prop, fontext, directory, fallback_to_default,\n                         rebuild_if_missing, rc_params):\n\n        prop = FontProperties._from_any(prop)\n\n        fname = prop.get_file()\n        if fname is not None:\n            return fname\n\n        if fontext == 'afm':\n            fontlist = self.afmlist\n        else:\n            fontlist = self.ttflist","sourceCodeStart":1554,"sourceCodeEnd":1590,"githubUrl":"https://github.com/matplotlib/matplotlib/blob/b379c1b69e012b142c0f496a52bcb30513802d72/lib/matplotlib/font_manager.py#L1554-L1590","documentation":"When font lookup finds no acceptable match, FontManager retries with the default family (DejaVu Sans) unless fallback_to_default=False, in which case _find_fonts_by_props raises ValueError. The error therefore means: the requested family (or font file) is not present in the current font cache/installed set and fallback was explicitly disabled.","triggerScenarios":"findfont(FontProperties(family='Arial'), fallback_to_default=False); mathtext or usetex output requesting a font absent from the cache; a newly installed OS font used before rebuilding the font cache.","commonSituations":"Minimal Docker/conda images without common fonts; fonts installed but the fontlist cache is stale; misspelled family names; MPLCONFIGDIR pointing at an empty directory.","solutions":["Install or register the font: font_manager.fontManager.addfont('/path/to/font.ttf') (rebuild cache if installed system-wide)","Delete the stale cache so it rescans: rm -rf ~/.cache/matplotlib","Verify the exact family name with font_manager.get_font_names() or sorted({f.name for f in fontManager.ttflist})","Leave fallback_to_default at its default True if a substitute is acceptable"],"exampleFix":"# before\nfont_manager.findfont(FontProperties(family='Roboto'), fallback_to_default=False)\n\n# after\nfrom matplotlib import font_manager as fm\nfm.fontManager.addfont('/usr/share/fonts/truetype/roboto/Roboto-Regular.ttf')\nfm.findfont(FontProperties(family='Roboto'), fallback_to_default=False)","handlingStrategy":"fallback","validationCode":"from matplotlib import font_manager as fm\navailable = {f.name for f in fm.fontManager.ttflist}\nif family not in available:\n    raise ValueError(f'{family!r} not installed; available: {sorted(available)[:10]} ...')","typeGuard":"def font_is_registered(family):\n    from matplotlib import font_manager as fm\n    return any(f.name == family for f in fm.fontManager.ttflist)","tryCatchPattern":"try:\n    path = fm.findfont(prop, fallback_to_default=False)\nexcept ValueError:\n    path = fm.findfont(prop)  # accept DejaVu Sans substitute","preventionTips":["Register custom fonts with fontManager.addfont at startup","Rebuild the cache after installing system fonts (delete ~/.cache/matplotlib)","Verify family names against get_font_names() before hardcoding them"],"tags":["matplotlib","fonts","font-not-found","fallback"],"backgroundTag":"font-not-found","analyzedSha":"b379c1b69e012b142c0f496a52bcb30513802d72","analyzedAt":"2026-08-21T23:31:55.468Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}