3b1b/manim · error
Invalid scene number
Error message
Invalid scene number
What it means
When multiple scenes exist and none is named on the command line, manim prints a numbered menu and reads a comma-separated selection. A token that is numeric indexes scene_classes[int(s) - 1]; an out-of-range number raises IndexError, which is caught, logged as 'Invalid scene number', and exits with status 2.
Source
Thrown at manimlib/extract_scene.py:54
return False
return True
def prompt_user_for_choice(scene_classes):
name_to_class = {}
max_digits = len(str(len(scene_classes)))
for idx, scene_class in enumerate(scene_classes, start=1):
name = scene_class.__name__
print(f"{str(idx).zfill(max_digits)}: {name}")
name_to_class[name] = scene_class
try:
user_input = input("\nSelect which scene to render (by name or number): ")
return [
name_to_class[split_str] if not split_str.isnumeric() else scene_classes[int(split_str) - 1]
for split_str in user_input.replace(" ", "").split(",")
]
except IndexError:
log.error("Invalid scene number")
sys.exit(2)
except KeyError:
log.error("Invalid scene name")
sys.exit(2)
except EOFError:
sys.exit(1)
def compute_total_frames(scene_class, scene_config):
"""
When a scene is being written to file, a copy of the scene is run with
skip_animations set to true so as to count how many frames it will require.
This allows for a total progress bar on rendering, and also allows runtime
errors to be exposed preemptively for long running scenes.
"""
pre_config = copy.deepcopy(scene_config)
pre_config["file_writer_config"]["write_to_movie"] = False
pre_config["file_writer_config"]["save_last_frame"] = FalseView on GitHub (pinned to dee01804d4)
Solutions
- Pick a number between 1 and the count shown in the menu
- Bypass the menu entirely by naming the scene: manim file.py MyScene
- In scripts, pass scene names via CLI args instead of relying on interactive stdin
Example fix
# before $ manim file.py # menu shows 1: A, 2: B > 3 # after $ manim file.py B
Defensive patterns
Strategy: validation
Validate before calling
choice = input("Scene number: ")
n = int(choice)
assert 1 <= n <= len(scene_classes), f"pick 1..{len(scene_classes)}" Type guard
def is_valid_scene_number(s: str, count: int) -> bool:
return s.isnumeric() and 1 <= int(s) <= count Prevention
- Pass scene names on the command line instead of relying on the interactive menu in scripts
- Count the printed menu entries before typing a number
When it happens
Trigger: Entering '5' or '0' when only 3 scenes are listed; entering '2,7' where 7 exceeds the count; leading zeros are fine but a number past the end is not.
Common situations: Miscounting the printed menu; piping a stale selection into stdin from a script that assumed an older scene list; typing the line number of the file instead of the menu number.
Related errors
- Invalid scene name
- No scene named {name} found
- Please use a valid color
- No 'class' found above {line_number}!
AI-assisted analysis of 3b1b/manim@dee01804d4 (2026-08-14).
Data as JSON: /api/errors/dc6d89325ff0af5e.
Report an issue: GitHub.