matplotlib.animation.FuncAnimation 在一台计算机上运行,​​但不在另一台计算机上运行

时间:2021-01-02 10:27:19

标签: python matplotlib anaconda

我目前做一些编程工作,涉及动画一系列矩阵。我使用 matplotlib.animation 中的函数 FuncAnimation 来做到这一点。令我困惑的是,据我所知,我的两台计算机都使用相同的配置。两者都使用 miniconda 和我需要的所有软件包。

我不时运行 conda update --all 以避免使用已弃用的代码。今天早上我在我的两台电脑上都这样做了,以确保我在两台电脑上都使用了相同的版本。但错误仍然存​​在。我试图做的是从这个矩阵序列生成一个 .mp4 文件。当我运行我的代码时,一切正常,除了一台计算机设法生成 .mp4 文件就好了,而另一台计算机返回以下错误:

MovieWriter ffmpeg unavailable; using Pillow instead.
Traceback (most recent call last):
  File "C:\ProgramData\Miniconda3\lib\site-packages\PIL\Image.py", line 2131, in save
    format = EXTENSION[ext]
KeyError: '.mp4'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "C:\ProgramData\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-c78d49ce4a1a>", line 1, in <module>
    runfile('C:/Users/jangr/OneDrive/Dokumente/ami/FZJ/Masterarbeit/Masterarbeit/phasefield_test.py', wdir='C:/Users/jangr/OneDrive/Dokumente/ami/FZJ/Masterarbeit/Masterarbeit')
  File "D:\Program Files\JetBrains\PyCharm 2020.3\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "D:\Program Files\JetBrains\PyCharm 2020.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Users/jangr/OneDrive/Dokumente/ami/FZJ/Masterarbeit/Masterarbeit/phasefield_test.py", line 124, in <module>
    test_solve_phase_field()
  File "C:/Users/jangr/OneDrive/Dokumente/ami/FZJ/Masterarbeit/Masterarbeit/phasefield_test.py", line 64, in test_solve_phase_field
    animate_interface(u_approx)
  File "C:\Users\jangr\OneDrive\Dokumente\ami\FZJ\Masterarbeit\Masterarbeit\phasefield_utils.py", line 81, in animate_interface
    ani.save('u.mp4')
  File "C:\ProgramData\Miniconda3\lib\site-packages\matplotlib\animation.py", line 1145, in save
    writer.grab_frame(**savefig_kwargs)
  File "C:\ProgramData\Miniconda3\lib\contextlib.py", line 120, in __exit__
    next(self.gen)
  File "C:\ProgramData\Miniconda3\lib\site-packages\matplotlib\animation.py", line 253, in saving
    self.finish()
  File "C:\ProgramData\Miniconda3\lib\site-packages\matplotlib\animation.py", line 554, in finish
    self._frames[0].save(
  File "C:\ProgramData\Miniconda3\lib\site-packages\PIL\Image.py", line 2133, in save
    raise ValueError(f"unknown file extension: {ext}") from e
ValueError: unknown file extension: .mp4

1 个答案:

答案 0 :(得分:0)

事实证明,我的一台计算机实际上缺少 ffmpeg 包。我从来没有费心去检查这个,因为我认为 matplotlib 需要的所有包都会随它一起安装,特别是因为我不记得曾经在我的另一台计算机上安装过 ffmpeg。无论如何,运行 conda install ffmpeg 解决了问题。