How was the most popular math video on B station 3Blue1Brown made?
Authorized repost from Zhihu user Li Gouhai
Original address: https://www.zhihu.com/question/57357012/answer/723888621
I believe many people know 3Blue1Brown, a YouTube channel created by Grant Sanderson, a mathematics student at Stanford University. The channel explains advanced mathematics from a unique visual perspective, including
linear algebra, calculus, neural networks, Riemann hypothesis, Fourier transform, quaternions,
etc.
I have gained a lot of inspiration from this video channel, and I have also developed a strong interest in its excellent video production technology.
By chance, I learned that there is a video production engine on Github: manim .
So, I suddenly wanted to try using this Python-based visualization engine. If the function can be realized, I can use this engine for animation demonstration according to my needs in the future.
I found some relevant articles online, some of which are well written, but because the open source code base is updated frequently, the previous configuration tutorials are often outdated. Now the latest version is based on Python 3 , and the previous tutorials based on Python 2.7 are no longer applicable to the current code. So during the installation process, I encountered many new problems, and I recorded the solutions to these new problems in the process of solving them. And formed this article. (Tested in June 2019)
Before configuration, you must first install Python 3. The installation process is not described here. It is recommended to install it through Anaconda instead of installing Python directly. The demonstration here is also based on the Windows 10 system and is completed on the basis of installing Anaconda. The download address of Anaconda is:
https://www.anaconda.com/distribution/#download-section
It is recommended to install Python 3.7 version. There are many specific steps online.
In addition, download:
-
manim : https://github.com/3b1b/manim, select clone or download, then Download ZIP, unzip it to a suitable location ( do not include Chinese characters in the path! ), and you can use it (this is all the files contained in the manim engine);
-
Miktex : https://miktex.org/download, just install it directly ( do not include Chinese characters in the path! ) (This is a Tex suite for Windows platform. TeX is a typesetting language, mainly used to process text information contained in videos);
-
ffmpeg : https://ffmpeg.zeranoe.com/builds/. After downloading, put it in a suitable path ( do not include Chinese characters in the path! ), unzip it and add the ../bin/ directory to the user environment variable (see the following figure) (this is the audio and video stream processing software)
-
dvisvgm : https://dvisvgm.de/Downloads/. 64-bit users should select the 64-bit installation package. After downloading, put it in a suitable path ( do not include Chinese characters in the path! ). After decompression, add the ../dvisvgm/ directory to the user environment variable (see the following figure) (this is the software that can convert dvi to high-quality svg).
How to add user environment variables
Right-click the "My Computer" icon - "Properties" - "Advanced System Settings" on the left
Select "Path" in "Environment Variables" - "User Variables" - "Edit" - "New".
Then add the path of the unzipped FFmpeg bin folder and the dvisvgm folder of dvisvgm, and select OK. Then perform an environment test to see if all dependent environments are configured properly (note: add according to the actual path of your personal installation, the figure is just a reference).
Configure and test via command line in Anaconda Prompt
The specific method is: right-click "Anaconda Prompt" - "More" - "Run as administrator"
This step is very important, because if you do not run it as an administrator, it is likely that you will have insufficient permissions, which will hinder the installation of subsequent packages.
Enter the following commands in the command line and press Enter to run:
python —version
latex —version
xelatex —version
ffmpeg -version
dvisvgm —version
If there are version prompts similar to the above, it means that the dependent software has been installed successfully. Otherwise, go back and check whether the installation or user path is added correctly.
Open the manim folder you downloaded and unzipped earlier, add a blank folder " media " to it, and create a new .txt file named "MEDIA_DIR.txt".
Enter the path of the newly created "media" folder in the "MEDIA_DIR.txt" file and save it.
Back in the Anaconda Prompt, enter:
cd <manim的根目录>
This command means: jump to the root directory of manim ( note: add it according to the actual path of your personal installation, the picture is just a reference ).
Then enter (if you can't see the entire code here on your phone, swipe left or right on the code or open the article on your computer):
python -m pip install -r requirements.txt
A common problem during this installation process is that the "pycairo" package is installed abnormally.
The solution is to first type and run:
conda install vs2015_runtime
Then install the "pycairo" package separately, enter and run:
conda install pycairo
Now that the basics are installed, try running a test command:
python -m manim example_scenes.py SquareToCircle -pl
At runtime, there may be errors such as: ModuleNotFoundError: No module named
pip install <pack name>
pip install pyreadline
python -m manim example_scenes.py SquareToCircle -pl
Now open the media folder and you will find the generated video, which shows an animation of a square turning into a circle:
Similarly, enter the command:
python -m manim example_scenes.py WarpSquare -pl
Get an animation of the mapping to the complex plane:
input the command:
python -m manim example_scenes.py WriteStuff -pl
During this process, you will be prompted to install some packages. To speed up the compilation process, you can click to uncheck the checkbox and install all the required packages by default. The result is a text animation with the classic 3b1b style:
input the command:
python -m manim example_scenes.py UpdatersExample -pl
You will get an animation of the data changing with the position of the graph:
Are you itching to try it? 23333.
If the installation is successful, thank you for your support. If you encounter any problems with the configuration, please leave a message in the comment area~
(Note: This tutorial is only for Windows 10 64-bit system)
3Blue1Brown
's B site homepage:
https://space.bilibili.com/88461692
-over-
AI Community | Communicate with outstanding people
AI Insider | Focus on industry development
Quantum Bit QbitAI · Toutiao signed author
Tracking new trends in AI technology and products
If you like it, click "Watching"!