项目简介
Manim 是一个 Python 动画引擎,用于制作精确的数学讲解视频。它提供了直观的语法来定义对象和动画,并通过 OpenGL 和 LaTeX 支持渲染高质量输出。
README 预览
\n \n \n \n\n\n[](https://pypi.org/project/manimgl/)\n[](http://choosealicense.com/licenses/mit/)\n[](https://www.reddit.com/r/manim/)\n[](https://discord.com/invite/bYCyhM9Kz2)\n[](https://3b1b.github.io/manim/)\n\nManim is an engine for precise programmatic animations, designed for creating explanatory math videos.\n\nNote, there are two versions of manim. This repository began as a personal project by the author of [3Blue1Brown](https://www.3blue1brown.com/) for the purpose of animating those videos, with video-specific code available [here](https://github.com/3b1b/videos). In 2020 a group of developers forked it into what is now the [community edition](https://github.com/ManimCommunity/manim/), 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](https://docs.manim.community/en/stable/faq/installation.html#different-versions) for more details.\n\n## Installation\n> [!Warning]\n> **WARNING:** These instructions are for ManimGL _only_. Trying to use these instructions to install [Manim Community/manim](https://github.com/ManimCommunity/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.\n\n> [!Note]\n> **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.\n\nManim runs on Python 3.10 or higher.\n\nSystem requirements are [FFmpeg](https://ffmpeg.org/), [OpenGL](https://www.opengl.org/) and [LaTeX](https://www.latex-project.org) (optional, if you want to use LaTeX).\nFor Linux, [Pango](https://pango.org) along with its development headers are required. See instruction [here](https://
常见问题 (5)
故障排除如何修复使用 pip install -e . 安装 Manim 后出现的 "ModuleNotFoundError: No module named 'trimesh' or 'pywavefront'" 错误?
该错误发生的原因是 trimesh 和 pywavefront 存在于 requirements.txt 中,但在 setup.cfg 的 install_requires 中缺失,因此可编辑安装(editable install)不会安装它们。
临时解决方法:
# 先激活你的虚拟环境
source venv/bin/activate # macOS/Linux
venv\Scripts\activate.bat # Windows 命令提示符
.\venv\Scripts\Activate.ps1 # Windows PowerShell
# 安装缺失的依赖
pip install trimesh pywavefront
永久修复:将这两个包添加到 setup.cfg 的 install_requires 中,然后重新安装:
pip install -e .该打包问题已在提交
4cec571c0 中修复;更新到包含该提交的版本同样可以解决此问题。故障排除为什么在 Manim 中使用 SVGMobject 加载 SVG 时,SVG 的 stroke(描边)会丢失?
在 Manim v1.7.2 中,SVGMobject 将 stroke_width 默认值设为 0.0,这会覆盖 SVG 内部定义的描边宽度。作为一种变通方法,可以传入 stroke_width=None,以保留 SVG 自身的描边宽度:
p = SVGMobject("Simple.svg", stroke_width=None)
永久修复方法是升级到包含 PR "Honor stroke widths declared in SVG files" 的 Manim 版本,该 PR 更改了默认行为,使解析出的逐路径描边宽度不再被重置为 0.0。
故障排除如何修复在 Python 3.13 上运行 manimgl 时出现的 "pkg_resources is deprecated as an API" 警告?
在软件包的 __init__.py 中,用现代的 importlib.metadata API 替换 pkg_resources:
try:
from importlib.metadata import version, PackageNotFoundError
except ImportError: # Python < 3.8
from importlib_metadata import version, PackageNotFoundError # type: ignore
try:
__version__ = version("manimgl")
except PackageNotFoundError:
__version__ = "unknown"
删除旧代码:
import pkg_resources
__version__ = pkg_resources.get_distribution("manimgl").version
对于早于 3.8 的 Python 版本,请使用 pip install importlib-metadata 安装向后移植版本。这可以消除 Python 3.13 及更高版本中的弃用警告。
故障排除如何修复在 Manim 中对 VectorField 使用 rotate_vector 时出现的 ValueError: shapes (N,2) and (3,3) not aligned 错误?
出现这种情况是因为 VectorField 会将所有采样点以形状为 (N, 2) 的批量数组传递给你的函数,而 rotate_vector 会尝试将其与 3×3 旋转矩阵相乘。请将 Manim 更新到包含批量 2D 旋转修复的最新 master:
pip install -U git+https://github.com/3b1b/manim.git
如果你是从本地克隆安装的:
git pull
pip install -e .
作为临时解决方案,可以直接应用 2D 旋转,而不是调用 rotate_vector:
def rotate_2d(vector, angle):
c, s = np.cos(angle), np.sin(angle)
rotation = np.array([
[c, -s],
[s, c],
])
return np.asarray(vector) @ rotation.T
def curl_func(p):
return rotate_2d(p / 3, PI / 2)
field_curl = VectorField(curl_func, axes)
此方法对单个向量和形状为 (N, 2) 的批量数组都有效。
故障排除在 Python 3.8 上安装 manim 时出现 "No matching distribution found for ipython>=8.18.0" 错误,该如何解决?
安装失败,因为 ipython>=8.18.0 需要 Python 3.9 或更高版本。请使用受支持的 Python 版本创建 Conda 环境;建议使用 Python 3.10,因为 manimlib 在 Python 3.9 上也可能导入失败:
conda create -n manim python=3.10
conda activate manim
pip install -e .
如果旧环境已存在,请先使用 conda env remove -n manim 将其删除,然后重新创建。