Rendering ManimGL in a notebook
Setup cell, once per kernel
from manimgl_jupyter import *
This gives every manimlib name plus the %%manim magic (alias %%manimgl). It
must come before any import of manimlib: manimlib parses sys.argv on import
and the kernel's arguments (VSCode passes --f=<file>) make it exit with
SystemExit: 2. If that already happened, restart the kernel and import
manimgl_jupyter first. %load_ext manimgl_jupyter works too, under the same rule.
Render cell
%%manim -l SceneName
class SceneName(Scene):
def construct(self):
...
- The cell body is ordinary Python, run in the notebook namespace first. Helper functions and constants defined in it stay available to later cells.
- Scene names are optional. Without one, every
Scenesubclass defined in the cell is rendered, in order.-arenders every scene defined so far. - Line form
%manim -s SceneNamerenders a scene defined in an earlier cell. - It always writes to file. No window opens;
self.embed(),-pand the interactive features are no-ops. - One render per cell is the natural unit. Keep
run_timeshort while iterating and use-l; switch to-mor--hdfor the final version.
Flags, identical to the manimgl command
| Flag | Effect |
|---|---|
-l -m --hd --uhd | 854x480, 1280x720, 1920x1080, 3840x2160 |
-r 1280x720 | any resolution |
--fps 60 | frame rate |
-s | skip animations, save the last frame as PNG |
-i | write a GIF |
-t | transparent background, .mov ProRes; not shown inline, the path is logged |
-c "#112233" | background color |
-n 3 or -n 3,6 | start at animation 3, or render animations 3 to 6 |
-a | render every scene (--write_all) |
--prerun | dry run first so the progress bar has a total |
--file_name NAME --video_dir DIR | output name and folder |
-q | no progress bar or "File ready" line |
%manim -h prints the full list. Paths with spaces go in quotes.
Output
Files land where manimgl -w would put them: videos/ next to the notebook
(the kernel's working directory), or what custom_config.yml in that directory
says. The result is embedded base64 in the cell output as <video> or <img>.
jupyter_config.media_width = "100%" # CSS max-width of what is shown, default "60%"
jupyter_config.media_embed = False # link the file instead of embedding it
jupyter_config.video_attributes = "controls loop" # default "controls autoplay loop"
VSCode cannot display linked local files, so keep media_embed = True there.
Linking suits JupyterLab and keeps the .ipynb small.
From Python instead of the magic:
path = render_scene(SceneName, "-l --fps 24") # returns the Path written, no display
show_media(path)
Troubleshooting
SystemExit: 2orambiguous option: --f=...on import: manimlib was imported beforemanimgl_jupyter. Restart the kernel; importmanimgl_jupyterfirst.UsageError: No Scene class named 'X': the name is misspelled, the class is not aScenesubclass, or it was defined inside a function. Define scenes at the top level of a cell. The message lists the scenes it does know.- Nothing shown, log says "Not shown in the notebook": the output is a
.movfrom-t; open the file fromvideos/. - Video area empty in VSCode:
jupyter_config.media_embedisFalse. - An exception inside
constructprints the usual traceback; aSceneName_temp.mp4is left behind, the same as the CLI. Fix and re-run. - Interrupting the kernel mid-render keeps and shows the partial video.
- The first render after import is slower: a GPU device is created and shaders
compiled per render;
TexandTextresults are cached on disk by manimlib. Texfails: LaTeX is not installed or not on the PATH.Textneeds no LaTeX.