{"id":"f3cb1a4e1f969591","repo":"pypa/pip","slug":"could-not-find-style-class-cls-r-in-style-module","errorCode":null,"errorMessage":"Could not find style class {cls!r} in style module.","messagePattern":"Could not find style class (.+?) in style module\\.","errorType":"exception","errorClass":"ClassNotFound","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/styles/__init__.py","lineNumber":53,"sourceCode":"    else:\n        for found_name, style in find_plugin_styles():\n            if name == found_name:\n                return style\n        # perhaps it got dropped into our styles package\n        builtin = \"\"\n        mod = 'pygments.styles.' + name\n        cls = name.title() + \"Style\"\n\n    try:\n        mod = __import__(mod, None, None, [cls])\n    except ImportError:\n        raise ClassNotFound(f\"Could not find style module {mod!r}\" +\n                            (builtin and \", though it should be builtin\")\n                            + \".\")\n    try:\n        return getattr(mod, cls)\n    except AttributeError:\n        raise ClassNotFound(f\"Could not find style class {cls!r} in style module.\")\n\n\ndef get_all_styles():\n    \"\"\"Return a generator for all styles by name, both builtin and plugin.\"\"\"\n    for v in STYLES.values():\n        yield v[1]\n    for name, _ in find_plugin_styles():\n        yield name\n","sourceCodeStart":35,"sourceCodeEnd":62,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/styles/__init__.py#L35-L62","documentation":"Pygments raises ClassNotFound (a ValueError subclass) from get_style_by_name when the style module imports successfully but does not expose the expected style class attribute. The expected class name is derived by title-casing the requested style name and appending 'Style' (e.g. 'monokai' -> 'MonokaiStyle'), so a typo, a renamed class, or a custom module missing that attribute triggers it.","triggerScenarios":"Calling pygments.styles.get_style_by_name(name) with a name that is neither in the built-in STYLE_MAP nor a plugin style, where the fallback import of 'pygments.styles.<name>' succeeds but the module lacks an attribute named '<Name.title()>Style'. Also triggered by HtmlFormatter(style='nonexistent') or any formatter/lexer that resolves a style by name.","commonSituations":"Typos in a style name passed to a formatter (e.g. 'monokia' instead of 'monokai'); third-party style plugins that define a class whose name does not match the '<Name>Style' convention; installing a custom style file into the package without the correctly-named class.","solutions":["Verify the style name against pygments.styles.get_all_styles() and correct the typo.","If using a custom style, ensure its class is named <Name.title()>Style inside a module under pygments.styles.","Register the style via a setuptools entry point in the 'pygments.styles' group so find_plugin_styles() can locate it."],"exampleFix":"// before\nformatter = HtmlFormatter(style='monokia')\n\n// after\nformatter = HtmlFormatter(style='monokai')","handlingStrategy":"validation","validationCode":"from pip._vendor.pygments.styles import get_all_styles\nvalid = set(get_all_styles())\nname = 'monokai'\nif name not in valid:\n    raise ValueError(f'unknown style {name!r}; choose from {sorted(valid)}')\nformatter = HtmlFormatter(style=name)","typeGuard":null,"tryCatchPattern":"from pip._vendor.pygments.util import ClassNotFound\ntry:\n    style = get_style_by_name(name)\nexcept ClassNotFound:\n    style = get_style_by_name('default')  # fallback style","preventionTips":["Validate style names against get_all_styles() before constructing formatters.","Centralize style-name selection behind a helper that maps your UI names to valid Pygments names.","Run a smoke test of style resolution at app startup."],"tags":["pygments","config","syntax-highlighting"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}