7

I tried adding text in Manim:

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

but I get a TextMobject is not defined error. What should I do?

Chris
  • 1,206
  • 2
  • 15
  • 35
A. G.
  • 73
  • 1
  • 6

3 Answers3

10

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

  • TexMobject is renamed to Tex, TextMobject is renamed to TexText
Dharman
  • 30,962
  • 25
  • 85
  • 135
giac
  • 4,261
  • 5
  • 30
  • 59
4

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.

onlyphantom
  • 8,606
  • 4
  • 44
  • 58
  • 'from manimlib.imports import *' This is already imported in the file provided: "example_scenes.py". Still it is showing this error – A. G. Feb 14 '21 at 11:18
  • @A.G. can you change that to `from manimlib import *` please? Can you also update your Question to include the complete code in `example_scenes.py` too so its easier to troubleshoot? – onlyphantom Feb 14 '21 at 11:27
  • updated the description, and replaced this line as well, but then the error changed to Scene is not defined – A. G. Feb 14 '21 at 11:36
  • I've edited my answer based on your latest input. I would recommend an update, or do a git clone and installation again. And then re-run your code with `from manimlib import *` instead or the older `from manimlib.imports import *`. – onlyphantom Feb 14 '21 at 11:45
  • 1
    Thanks for the update, actually there was difference in class name. I was using TextMobject, but actually it was only text – A. G. Feb 14 '21 at 12:51
  • I have the same issue, and I just installed the new version. How did you solve it? – giac Feb 23 '21 at 15:14
3

I too am pretty new to manim and ran into this exact same issue. I found that you can replace TextMobject with Tex or Text. I'm not sure exactly what the difference is, but they seem to be rendered with a slightly different font size. I got an error trying to use TexText.

DJElectric
  • 349
  • 1
  • 4
  • 18