3b1b/manim · error · Exception

Must specify either a file_name or svg_string SVGMobject

Error message

Must specify either a file_name or svg_string SVGMobject

What it means

Raised by SVGMobject.__init__ (svg_mobject.py:97) when neither the svg_string parameter, nor the file_name parameter, nor the class-level self.file_name attribute is non-empty. The constructor needs exactly one SVG source; with all three empty there is nothing to parse.

Source

Thrown at manimlib/mobject/svg/svg_mobject.py:97

            color=None,
            opacity=None,
            fill_color=None,
            fill_opacity=None,
            stroke_width=None,
            stroke_color=None,
            stroke_opacity=None,
        ),
        path_string_config: dict = dict(),
        **kwargs
    ):
        if svg_string != "":
            self.svg_string = svg_string
        elif file_name != "":
            self.svg_string = self.file_name_to_svg_string(file_name)
        elif self.file_name != "":
            self.svg_string = self.file_name_to_svg_string(self.file_name)
        else:
            raise Exception("Must specify either a file_name or svg_string SVGMobject")

        self.svg_default = dict(svg_default)
        self.path_string_config = dict(path_string_config)

        super().__init__(**kwargs)
        self.init_svg_mobject()
        self.ensure_positive_orientation()

        # Initialize position
        height = height or self.height
        width = width or self.width

        initial_height = self.get_height()

        if should_center:
            self.center()
        if height is not None:
            self.set_height(height)

View on GitHub (pinned to dee01804d4)

Solutions

  1. Pass the SVG explicitly: SVGMobject('my_icon.svg') or SVGMobject(svg_string='<svg ...>...')
  2. In subclasses, set the class attribute: class MyIcon(SVGMobject): file_name = 'my_icon.svg'
  3. Check inputs before construction: assert svg_string or file_name

Example fix

# before
class Logo(SVGMobject):
    pass  # forgot file_name
Logo()  # raises

# after
class Logo(SVGMobject):
    file_name = 'logo.svg'
Logo()
Defensive patterns

Strategy: validation

Validate before calling

assert svg_string or file_name or getattr(cls, 'file_name', ''), \
    'SVGMobject needs svg_string, file_name arg, or class-level file_name'

Prevention

When it happens

Trigger: Calling SVGMobject() directly; subclassing SVGMobject but forgetting to set the class attribute file_name = 'my_icon.svg'; passing file_name='' explicitly.

Common situations: Creating a reusable SVGMobject subclass where the author intended to set file_name as a class field but omitted it; passing a file_name that is falsy after a bug in path-building code.

Related errors


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