3b1b / manim

3b1b / manim

Manim is an engine for precise programmatic animations, designed for creating explanatory math videos. Note, there are two versions of manim. This repository began as a personal project by the author of 3Blue1Brown for the purpose of animating those videos, with video-specific code available here. In 2020 a group of developers forked it into what is now the community edition, with a goal of being more stable, better tested, quicker to respond to community contributions, and all around friendlier to get started with. See this page for more details.

Manim 是一个用于精确编程动画的引擎,专为制作数学解释视频而设计。请注意,Manim 有两个版本。本仓库最初是 3Blue1Brown 作者的一个个人项目,旨在为那些视频制作动画,视频相关的代码可以在这里找到。2020 年,一群开发者将其分叉(fork)成了现在的社区版(Community Edition),目标是使其更稳定、测试更完善、对社区贡献的响应更快,并且在上手方面更加友好。更多详情请参阅此页面。

Installation Warning

WARNING: These instructions are for ManimGL only. Trying to use these instructions to install Manim Community/manim or instructions there to install this version will cause problems. You should first decide which version you wish to install, then only follow the instructions for your desired version.

安装警告

警告:这些说明仅适用于 ManimGL。尝试使用这些说明来安装 Manim Community/manim,或者使用那边的说明来安装此版本都会导致问题。你应该先决定要安装哪个版本,然后仅遵循你所选版本的说明进行操作。

Note: To install manim directly through pip, please pay attention to the name of the installed package. This repository is ManimGL of 3b1b. The package name is manimgl instead of manim or manimlib. Please use pip install manimgl to install the version in this repository.

注意:若要直接通过 pip 安装 manim,请注意安装包的名称。本仓库是 3b1b 的 ManimGL,包名为 manimgl 而不是 manimmanimlib。请使用 pip install manimgl 来安装本仓库的版本。

Manim runs on Python 3.10 or higher. System requirements are FFmpeg, OpenGL and LaTeX (optional, if you want to use LaTeX). For Linux, Pango along with its development headers are required. See instruction here.

Manim 运行在 Python 3.10 或更高版本上。系统要求包括 FFmpeg、OpenGL 和 LaTeX(可选,如果你想使用 LaTeX 的话)。对于 Linux,需要 Pango 及其开发头文件。请参阅此处的说明。

Directly

# Install manimgl
pip install manimgl
# Try it out
manimgl

直接安装

# 安装 manimgl
pip install manimgl
# 尝试运行
manimgl

For more options, take a look at the Using manim sections further below. If you want to hack on manimlib itself, clone this repository and in that directory execute:

# Install manimgl
pip install -e .
# Try it out
manimgl example_scenes.py OpeningManimExample
# or
manim-render example_scenes.py OpeningManimExample

如需更多选项,请查看下方的“使用 manim”部分。如果你想对 manimlib 本身进行修改,请克隆此仓库并在该目录下执行:

# 安装 manimgl
pip install -e .
# 尝试运行
manimgl example_scenes.py OpeningManimExample
# 或者
manim-render example_scenes.py OpeningManimExample

Linux (Ubuntu/Debian)

Install system dependencies.

sudo apt update
sudo apt install ffmpeg
sudo apt install python3-pip
sudo apt install libpango1.0-dev

Install a lightweight LaTeX distribution (optional, for LaTeX rendering).

sudo apt install texlive-science texlive-fonts-extra texlive-latex-extra

This lightweight setup is significantly smaller than installing texlive-full while still supporting most Manim projects.

Linux (Ubuntu/Debian)

安装系统依赖:

sudo apt update
sudo apt install ffmpeg
sudo apt install python3-pip
sudo apt install libpango1.0-dev

安装轻量级 LaTeX 发行版(可选,用于 LaTeX 渲染):

sudo apt install texlive-science texlive-fonts-extra texlive-latex-extra

这种轻量级配置比安装 texlive-full 小得多,同时仍能支持大多数 Manim 项目。

Clone and install ManimGL.

git clone https://github.com/3b1b/manim.git
cd manim
python3 -m pip install -e .
manimgl example_scenes.py OpeningManimExample

克隆并安装 ManimGL:

git clone https://github.com/3b1b/manim.git
cd manim
python3 -m pip install -e .
manimgl example_scenes.py OpeningManimExample

💡 Optional: Using a virtual environment (venv) It is recommended to use a virtual environment to avoid conflicts with system packages.

sudo apt install python3-venv
python3 -m venv venv
source venv/bin/activate
python3 -m pip install -e .

If python3-venv is unavailable on your system, try installing the version-specific package instead:

sudo apt install python3.12-venv

💡 可选:使用虚拟环境 (venv) 建议使用虚拟环境以避免与系统包冲突。

sudo apt install python3-venv
python3 -m venv venv
source venv/bin/activate
python3 -m pip install -e .

如果你的系统上没有 python3-venv,请尝试安装特定版本的包:

sudo apt install python3.12-venv

Directly (Windows)

Install FFmpeg. Install a LaTeX distribution. MiKTeX is recommended. Install the remaining Python packages.

git clone https://github.com/3b1b/manim.git
cd manim
pip install -e .
manimgl example_scenes.py OpeningManimExample

直接安装 (Windows)

安装 FFmpeg。安装 LaTeX 发行版(推荐 MiKTeX)。安装剩余的 Python 包:

git clone https://github.com/3b1b/manim.git
cd manim
pip install -e .
manimgl example_scenes.py OpeningManimExample

Mac OSX

Install FFmpeg, LaTeX in terminal using homebrew.

brew install ffmpeg mactex

💡 An alternative to heavyweight MacTeX bundle. To avoid installing the full MacTeX bundle, which is ~6GB, you can alternatively install the lightweight BasicTeX and then gradually add only the LaTeX packages you actually need. A list of packages sufficient to run examples can be found here. For an overview of the MacTeX installer bundles, see https://www.tug.org/mactex/.

Mac OSX

使用 homebrew 在终端安装 FFmpeg 和 LaTeX:

brew install ffmpeg mactex

💡 MacTeX 大礼包的替代方案 为了避免安装约 6GB 的完整 MacTeX 大礼包,你可以选择安装轻量级的 BasicTeX,然后根据需要逐步添加所需的 LaTeX 包。运行示例所需的包列表可以在这里找到。有关 MacTeX 安装包的概述,请参阅 https://www.tug.org/mactex/。

If you are using an ARM-based processor, install Cairo.

arch -arm64 brew install pkg-config cairo

Install latest version of manim using these command.

git clone https://github.com/3b1b/manim.git
cd manim
pip install -e .
manimgl example_scenes.py OpeningManimExample

(make sure to add manimgl to path first.)

如果你使用的是 ARM 架构处理器,请安装 Cairo:

arch -arm64 brew install pkg-config cairo

使用以下命令安装最新版本的 manim:

git clone https://github.com/3b1b/manim.git
cd manim
pip install -e .
manimgl example_scenes.py OpeningManimExample

(请确保先将 manimgl 添加到环境变量 PATH 中。)

Anaconda Install

Install LaTeX as above. Create a conda environment using conda create -n manim python=3.10. Activate the environment using conda activate manim. Install manimgl using pip install -e ..

Anaconda 安装

按上述方法安装 LaTeX。使用 conda create -n manim python=3.10 创建 conda 环境。使用 conda activate manim 激活环境。使用 pip install -e . 安装 manimgl。

Using manim

Try running the following:

manimgl example_scenes.py OpeningManimExample

This should pop up a window playing a simple scene. Look through the example scenes to see examples of the library’s syntax, animation types and object types.

使用 manim

尝试运行以下命令:

manimgl example_scenes.py OpeningManimExample

这应该会弹出一个窗口播放一个简单的场景。浏览示例场景,查看该库的语法、动画类型和对象类型的示例。

In the 3b1b/videos repo, you can see all the code for 3blue1brown videos, though code from older videos may not be compatible with the most recent version of manim. The readme of that repo also outlines some details for how to set up a more interactive workflow, as shown in this manim demo video for example.

在 3b1b/videos 仓库中,你可以看到 3blue1brown 视频的所有代码,尽管旧视频的代码可能与最新版本的 manim 不兼容。该仓库的自述文件还概述了一些关于如何设置更具交互性工作流的细节,例如此 manim 演示视频所示。

When running in the CLI, some useful flags include:

  • -w to write the scene to a file
  • -o to write the scene to a file and open the result
  • -s to skip to the end and just show the final frame.
  • -so will save the final frame to an image and show it
  • -n <number> to skip ahead to the n’th animation of a scene.
  • -f to make the playback window fullscreen

在命令行运行程序时,一些有用的标志包括:

  • -w:将场景写入文件
  • -o:将场景写入文件并打开结果
  • -s:跳到结尾并仅显示最后一帧
  • -so:将最后一帧保存为图像并显示
  • -n <number>:跳到场景的第 n 个动画
  • -f:使播放窗口全屏

Take a look at custom_config.yml for further configuration. To add your customization, you can either edit this file, or add another file by the same name “custom_config.yml” to whatever directory you are running manim from. For example this is the one for 3blue1brown videos. There you can specify where videos should be output to, where manim should look for image files and sounds you want to read in, and other defaults regarding style and video quality.

查看 custom_config.yml 以进行进一步配置。要添加自定义设置,你可以编辑此文件,或者在运行 manim 的目录下添加另一个同名文件 “custom_config.yml”。例如,这是 3blue1brown 视频所使用的配置文件。你可以在其中指定视频的输出位置、manim 查找图像和声音文件的路径,以及关于样式和视频质量的其他默认设置。

Documentation

Documentation is in progress at 3b1b.github.io/manim. And there is also a Chinese version maintained by @manim-kindergarten: docs.manim.org.cn (in Chinese). manim-kindergarten wrote and collected some useful extra classes and some codes of videos in manim_sandbox repo.

文档

文档正在 3b1b.github.io/manim 持续完善中。此外,还有一个由 @manim-kindergarten 维护的中文版本:docs.manim.org.cn。manim-kindergarten 在 manim_sandbox 仓库中编写并收集了一些有用的额外类和视频代码。

Contributing

Is always welcome. As mentioned above, the community edition has the most active ecosystem for contributions, with testing and continuous integration, but pull requests are welcome here too. Please explain the motivation for a given change and examples of its effect.

贡献

随时欢迎贡献。如上所述,社区版拥有最活跃的贡献生态系统,包含测试和持续集成,但这里也欢迎提交 Pull Request。请解释所做更改的动机并提供效果示例。

License

This project falls under the MIT license.

许可证

本项目采用 MIT 许可证。