Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextMobject is not defined in Manim

Tags:

python

manim

I just started to learn manim and I saw the first video in which we create a class in example_scenes.py. When i tried running it, it is saying that name TextMobject is not defined. What should I do?

Class I created:

class FirstScene(Scene):
    def construct(self):
        text=TextMobject("text")
        self.add(text) 

Code used in conda prompt:

python -m manim example_scenes.py FirstScene -w

Please check this file for the class "FirstScene" (last class of this file) i am trying to run.

like image 896
A. G. Avatar asked Dec 07 '22 09:12

A. G.


2 Answers

I found this just in case in the file whatsnew.rst

  • TexMobject is renamed to Tex, TextMobject is renamed to TexText
like image 91
giac Avatar answered Dec 14 '22 05:12

giac


The error is quite straightforward.

"TextMobject" is not defined

This is a complaint that you TextMobject is not defined anywhere in your code, nor was it imported.

EDIT

After additional comments and information, the problem is that the manim library has updated and the current version has restructured its internal code organization. The guide that you linked to referenced an older version of manim where you would do from manimlib.imports import as if there was a separate imports.py.

The updated version however, would require you to do: manimlib import *. This is confirmed by checking the official repository's guide. As well, this is the updated examples_scene.py, again from it's official repository.

from manimlib import *

class FirstScene(Scene):
    def construct(self):
        text=TextMobject("text")
        self.add(text) 

If it complains about Scene not found, check that you have the latest version of the package installed (git clone again and re-install if you're using an outdated version). If you want to explicitly import it, the latest version points to Scene being at this location (https://github.com/3b1b/manim/blob/master/manimlib/scene/scene.py), so your import path would be manimlib.scene.scene:

from manimlib.scene.scene import Scene

However, should you use from manimlib import * this would have been imported as well without you making explicit imports.

You can confirm this on the the package's __init__.py, linked here:

...
from manimlib.scene.scene import *
...

Either way, TextMobject should either be defined by you, or imported before you use it. I recommend you do an update, and then try again with the code above.

EDIT 2

In addition to the changes in how you import Scene, according to @giac's answer, TexMobject is renamed to Tex and TextMobject is renamed to TexText. I wouldn't count on it being still true or being the only changes so I recommend you check the official repository's guide if you stumbled here trying to get an answer.

like image 27
onlyphantom Avatar answered Dec 14 '22 04:12

onlyphantom