Manim: 一个数学可视化的动画引擎
官网:https://3b1b.github.io/manim/index.html
名词解析
- python3.7是python语言的解释器, 运行python程序的环境必备品. 这个没啥说的,大家都能懂. 虽然官方建议3.7,但是我用3.8发现也没问题.考虑未来的历史进程,大伙最好还是装3.8的版本吧.
- pip ,用来管理包(又叫"库").python的伟大之处在于其免费(点赞也不要钱). 所以人人可用, 大家都用, 就有人们开发出来了各种强大的python库.使用这些库我们就可以用少量代码实现人脸识别之类的高级功能. 解放了人类的劳动力到更高级的工作上,而不是天天写重复的低级代码. 而这些库, 一般就是用pip来安装的. 现在介绍pip,后文将教大家咋用. 如果你学过python的话,应该已经会用了.
- FFmpeg, 著名的开源视频流处理内核. 内核代表这东西几乎无法独立运行. 但是它却可以作为其他程序的心脏去工作.比如作为VLC, 或者一些录屏软件,剪辑软件的内核. Manim的视频渲染就是基于它的接口的.
- sox,一个小巧的用于处理音频的软件.
- TeX宏集. 对于大部分人来说可能比较陌生. 这个是用来用编程的方式输出高质量论文的一种语言/程序. 尤其擅长渲染复杂的公式. Manim需要TeX环境处理公式和文字. 不像Microsoft office word 那样的所见即所得文字处理程序, TeX通过代码描述文章,然后直接渲染出来可视化的效果.比如MiKTeX直接输出pdf文档,Manim直接输出图片或者视频.
借鉴:做出高逼格的数学动画——一起来学manim·入门篇(一)
安装Manim软件
借鉴:Python视频制作引擎Manim安装教程
就借鉴这个就行:https://zhuanlan.zhihu.com/p/181536479
通过git bash运行下面命令【git bash安装看这里】
git clone https://github.com/3b1b/manim.git
cd manim
# 安装python依赖
pip install -e .
python -m pip install -r requirements.txt
ffmpeg
sox
Tex支持
pycairo
全局使用manimlib
调整区域配置,解决上述问题
下载源代码
git bash失败,就得尝试zip下载,多尝试几次
路径不对
PS C:\Users\18826> manim example_scenes.py SquareToCircle -p
Traceback (most recent call last):
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\Scripts\manim.exe\__main__.py", line 7, in <module>
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\lib\site-packages\manimlib\__init__.py", line 9, in main
config = manimlib.config.get_configuration(args)
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\lib\site-packages\manimlib\config.py", line 155, in get_configuration
module = get_module(args.file)
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\lib\site-packages\manimlib\config.py", line 150, in get_module
spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 846, in exec_module
File "<frozen importlib._bootstrap_external>", line 982, in get_code
File "<frozen importlib._bootstrap_external>", line 1039, in get_data
FileNotFoundError: [Errno 2] No such file or directory: 'example_scenes.py'
测试
出现下述动态图
ManimGL v1.6.1
[08:32:12] INFO Using the default configuration file, which config.py:362
you can modify in
`c:\users\18826\manim\manimlib\default_config
.yml`
INFO If you want to create a local configuration config.py:363
file, you can create a file named
`custom_config.yml`, or run `manimgl
--config`
WARNING You may be using Windows platform and have config.py:327
not specified the path of
`temporary_storage`, which may cause OSError.
So it is recommended to specify the
`temporary_storage` in the config file (.yml)
[08:32:13] WARNING You may be using Windows platform and have config.py:327
not specified the path of
`temporary_storage`, which may cause OSError.
So it is recommended to specify the
`temporary_storage` in the config file (.yml)
INFO Using the default configuration file, which config.py:362
you can modify in
`c:\users\18826\manim\manimlib\default_config
.yml`
INFO If you want to create a local configuration config.py:363
file, you can create a file named
`custom_config.yml`, or run `manimgl
--config`
WARNING You may be using Windows platform and have config.py:327
not specified the path of
`temporary_storage`, which may cause OSError.
So it is recommended to specify the
`temporary_storage` in the config file (.yml)
[08:32:18] WARNING You may be using Windows platform and have config.py:327
not specified the path of
`temporary_storage`, which may cause OSError.
So it is recommended to specify the
`temporary_storage` in the config file (.yml)
Traceback (most recent call last):
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\Scripts\manimgl.exe\__main__.py", line 7, in <module>
File "C:\Users\18826\manim\manimlib\__main__.py", line 25, in main
scene.run()
File "C:\Users\18826\manim\manimlib\scene\scene.py", line 160, in run
self.construct()
File "example_scenes.py", line 29, in construct
IntegerMatrix(matrix, include_background_rectangle=True),
File "C:\Users\18826\manim\manimlib\mobject\matrix.py", line 204, in __init__
super().__init__(matrix, element_alignment_corner=element_alignment_corner, **kwargs)
File "C:\Users\18826\manim\manimlib\mobject\matrix.py", line 99, in __init__
self.add_brackets(bracket_v_buff, bracket_h_buff)
File "C:\Users\18826\manim\manimlib\mobject\matrix.py", line 144, in add_brackets
brackets = Tex("".join((
File "C:\Users\18826\manim\manimlib\mobject\svg\tex_mobject.py", line 57, in __init__
super().__init__(
File "C:\Users\18826\manim\manimlib\mobject\svg\string_mobject.py", line 68, in __init__
super().__init__(
File "C:\Users\18826\manim\manimlib\mobject\svg\svg_mobject.py", line 76, in __init__
self.init_svg_mobject()
File "C:\Users\18826\manim\manimlib\mobject\svg\svg_mobject.py", line 105, in init_svg_mobject
submobs = self.mobjects_from_file(self.get_file_path())
File "C:\Users\18826\manim\manimlib\mobject\svg\string_mobject.py", line 78, in get_file_path
return self.get_file_path_by_content(self.get_content(is_labelled))
File "C:\Users\18826\manim\manimlib\mobject\svg\tex_mobject.py", line 85, in get_file_path_by_content
return tex_content_to_svg_file(
File "C:\Users\18826\manim\manimlib\utils\tex_file_writing.py", line 82, in tex_content_to_svg_file
with display_during_execution("Writing " + short_tex):
File "C:\Users\18826\AppData\Local\Programs\Python\Python39\lib\contextlib.py", line 119, in __enter__
return next(self.gen)
File "C:\Users\18826\manim\manimlib\utils\tex_file_writing.py", line 153, in display_during_execution
max_characters = os.get_terminal_size().columns - 1
OSError: [WinError 6]
检验Manim是否安装成功
1.创建一个名为example.py 的文件,把以下内容复制进去
from manim import *
class SquareToCircle(Scene):
def construct(self):
circle = Circle()
square = Square()
square.flip(RIGHT)
square.rotate(-3 * TAU / 8)
circle.set_fill(PINK, opacity=0.5)
self.play(Create(square))
self.play(Transform(square, circle))
self.play(FadeOut(square))
2.在刚才创建的example.py所在的文件夹里边右键运行【在终端打开】
执行遇到问题
no module named “manimlib”
需要将该文件放到软件安装的目录下,比如,本次软件安装在自己创建的manim文件夹中
【manim】导入库时出现ModuleNotFoundError: No module named‘manimlib.XXX‘解决方法