3b1b/manim · warning

No 'class' found above {line_number}!

Error message

No 'class' found above {line_number}!

What it means

With the -e <line_number> option, manim injects an embed() call at that line; when no scene names were given, it scans backwards through the file's lines for the nearest top-level 'class ' statement to infer the containing scene. If no line above the given line starts with 'class', it logs 'No 'class' found above {line_number}!' and cannot infer the scene name.

Source

Thrown at manimlib/extract_scene.py:173

    # Add the relevant embed line to the code
    indent = get_indent(lines, line_number)
    lines.insert(line_number, indent + "self.embed()")
    new_code = "\n".join(lines)

    # When the user executes the `-e <line_number>` command
    # without specifying scene_names, the nearest class name above
    # `<line_number>` will be automatically used as 'scene_names'.

    if not run_config.scene_names:
        classes = list(filter(lambda line: line.startswith("class"), lines[:line_number]))
        if classes:
            from re import search

            scene_name = search(r"(\w+)\(", classes[-1])
            run_config.update(scene_names=[scene_name.group(1)])
        else:
            log.error(f"No 'class' found above {line_number}!")

    # Execute the code, which presumably redefines the user's
    # scene to include this embed line, within the relevant module.
    code_object = compile(new_code, module.__name__, 'exec')
    exec(code_object, module.__dict__)


def get_module(run_config: Dict) -> Module:
    module = ModuleLoader.get_module(run_config.file_name, run_config.is_reload)
    if run_config.embed_line:
        insert_embed_line_to_module(module, run_config)
    return module


def main(scene_config: Dict, run_config: Dict):
    module = get_module(run_config)
    all_scene_classes = get_scene_classes(module)
    scenes = get_scenes_to_render(all_scene_classes, scene_config, run_config)

View on GitHub (pinned to dee01804d4)

Solutions

  1. Point -e at a line at or below the class definition of the scene you want, e.g. inside construct()
  2. Or name the scene explicitly so no inference is needed: manim file.py MyScene -e 42
  3. Re-check the line number after editing the file — it refers to the current file's lines

Example fix

# before
$ manim file.py -e 3        # line 3 is above 'class MyScene'
# after
$ manim file.py MyScene -e 10  # line 10 is inside MyScene.construct
Defensive patterns

Strategy: validation

Validate before calling

with open(path) as f:
    lines = f.readlines()
assert any(l.startswith("class") for l in lines[:embed_line]), "no class above the embed line"

Prevention

When it happens

Trigger: Running manim file.py -e 5 where line 5 precedes any class definition; pointing -e at a line inside module-level helper functions at the top of the file; files where the class line is indented or uses a decorator-only header.

Common situations: Trying to embed very early in a file to debug setup code; running -e against a script organized with imports/constants before any Scene subclass; line-number drift after edits (the number now points above the class).

Related errors


AI-assisted analysis of 3b1b/manim@dee01804d4 (2026-08-14). Data as JSON: /api/errors/2d3e398f7f40e9c3. Report an issue: GitHub.