Fix My Tutorial
Report

Embedding Matplotlib Animations in IPython Notebooks

Open the original tutorial
Fixed Python 3.12 · checked 17 Oct 2026 · model cost $0.062

After applying the fixes, the tutorial now runs successfully under Python 3.12. Initially it failed because the IPython package was missing, causing a ModuleNotFoundError when importing IPython.display, and because the code used the deprecated bytes.encode('base64') method, which was removed in Python 3, leading to an AttributeError. The repairs installed IPython via pip and replaced the obsolete encoding call with base64.b64encode().decode('ascii'), resolving both issues.

2 changes to make it work today

Install matplotlib and numpy

s2 · shell migrate

Add ipython to the pip install command so that the IPython module is available for step s5.

@@ -1 +1 @@
-pip install matplotlib numpy
+pip install matplotlib numpy ipython

Sources

Define anim_to_html function and VIDEO_TAG

s4 · run_code migrate

Replace deprecated bytes.encode('base64') with base64.b64encode().decode('ascii') for Python 3 compatibility.

@@ -1,3 +1,4 @@
from tempfile import NamedTemporaryFile
+import base64
VIDEO_TAG = """<video controls>
@@ -11,5 +12,5 @@
anim.save(f.name, fps=20, extra_args=['-vcodec', 'libx264'])
video = open(f.name, "rb").read()
- anim._encoded_video = video.encode("base64")
+ anim._encoded_video = base64.b64encode(video).decode('ascii')
return VIDEO_TAG.format(anim._encoded_video)

Tell the author

Send them what broke and the fix, so the next reader doesn't hit the same error.

Badge

Add it to the tutorial so readers know when it was last checked.

Fix My Tutorial badge
Markdown
[![Fix My Tutorial](https://fix-my-tutorial.onrender.com/badge/ri-bbshDjRt.svg)](https://fix-my-tutorial.onrender.com/r/ri-bbshDjRt)
HTML
<a href="https://fix-my-tutorial.onrender.com/r/ri-bbshDjRt"><img src="https://fix-my-tutorial.onrender.com/badge/ri-bbshDjRt.svg" alt="Fix My Tutorial"></a>