Search code examples
pythonmanim

Manim (manimlib version) not working as it should


Everything seemed to be installed correctly, and when launch rendering, I get this error:

File "c:\users\oussa\appdata\local\programs\python\python37\lib\site-packages\manimlib\extract_scene.py", line 155, in main
    scene = SceneClass(**scene_kwargs)
  File "c:\users\oussa\appdata\local\programs\python\python37\lib\site-packages\manimlib\scene\scene.py", line 75, in __init__
    self.construct()
  File "testM.py", line 5, in construct
    text = TextMobject("I literally h8 u.")
  File "c:\users\oussa\appdata\local\programs\python\python37\lib\site-packages\manimlib\mobject\svg\tex_mobject.py", line 150, in __init__
    self.break_up_by_substrings()
  File "c:\users\oussa\appdata\local\programs\python\python37\lib\site-packages\manimlib\mobject\svg\tex_mobject.py", line 190, in break_up_by_substrings
    sub_tex_mob.move_to(self.submobjects[last_submob_index], RIGHT)
IndexError: list index out of range

And that's the Python code of the program running:

from manimlib.imports import *

class TestScene(Scene):
  def construct(self):
    text = TextMobject("I literally h8 u.")
    text.scale(2)

    self.play(Write(text))
    self.wait()

class TestScene2(Scene):
  def construct(self):
    text = TextMobject("I literally $$3 u.")
    text.scale(2)

    self.play(Write(text))
    self.wait()

What is the problem?


Solution

  • Your code doesn't actually do anything, as it's just a bunch of class definitions. By the way, you probably want to start using standard Python indents of 4 instead of 2, it'll save you headaches later.

    Installing manim, your code doesn't actually work, but if the import statement is replaced with from manim import *, you instantiate an object and replace the TextMobject with Text, it runs and renders some videos after calling construct().

    I replaced it with a more focused import as doing a import * is generally a bad idea.

    from manim import Scene, Text, Write
    
    
    class TestScene(Scene):
        def construct(self):
            text = Text("I literally h8 u.")
            text.scale(2)
        
            self.play(Write(text))
            self.wait()
    
    class TestScene2(Scene):
        def construct(self):
            text = Text("I literally $$3 u.")
            text.scale(2)
        
            self.play(Write(text))
            self.wait()
    
    
    ts = TestScene()
    ts.construct()
    

    I was using Python 3.9.7 (no reason, just the version my environment had) and manim 0.12.0.

    I'd say manim looks like a pretty janky package though, so I'd expect some more weird issues.