【问题标题】:Matplotlib animation error "Requested MovieWriter (ffmpeg) not available"Matplotlib 动画错误“请求的 MovieWriter (ffmpeg) 不可用”
【发布时间】:2020-10-01 22:36:33
【问题描述】:

我正在尝试使用 matplotlib FuncAnimation 运行动画,但一直遇到错误 “请求的 MovieWriter (ffmpeg) 不可用”。我知道这个问题之前有人问过,我查看了对此的每一个回复,但没有一个有效。

我在 Windows 10 上运行 jupyter notebook

我有以下代码。

from matplotlib.animation import FuncAnimation

def init():
    ax.clear()
    nice_axes(ax)
    ax.set_ylim(.2, 6.8)

def update(i):
    for bar in ax.containers:
        bar.remove()
    y = df_rank_expanded.iloc[i]
    width = df_expanded.iloc[i]
    ax.barh(y=y, width=width, color=colors, tick_label=labels)
    date_str = df_expanded.index[i].strftime('%B %-d, %Y')
    ax.set_title(f'Racial Unemployment - {date_str}', fontsize='smaller')

fig = plt.Figure(figsize=(4, 2.5), dpi=144)
ax = fig.add_subplot()
anim = FuncAnimation(fig=fig, func=update, init_func=init, frames=len(df_expanded), 
                     interval=100, repeat=False) 

当我跑步时

from IPython.display import HTML
HTML(anim.to_html5_video())

我收到错误 RuntimeError: Requested MovieWriter (ffmpeg) not available

这是我尝试过的。 1)在我的系统上安装ffmpeg,并设置路径值。我按照这里的说明进行操作https://www.wikihow.com/Install-FFmpeg-on-Windows 我通过在 cmd 窗口中输入 ffmpeg -version 验证了 FFmpeg 已安装 2) conda install -c conda-forge ffmpeg

这仍然会导致 ffmpeg 不可用错误。

3) 我已按照此处的说明进行操作 Matplotlib-Animation "No MovieWriters Available" 上面说要做 1 和 2 4) 这里Stop Matplotlib Jupyter notebooks from showing plot with animation 这建议使用

HTML(anim.to_jshtml())

但是,这给了我 date_str = df_expanded.index[i].strftime('%B %-d, %Y') 的无效格式字符串错误

5)我已经直接在jupyter notebook中设置了路径变量

plt.rcParams['animation.ffmpeg_path'] = 'C:\FFmpeg\ffmpeg-20200610-9dfb19b-win64-static\bin\ffmpeg.exe'

6) 重启我的内核 7) 重新启动我的系统 8) 把我的电脑打成小块,用工业粉碎机把它们磨碎,烧掉碎片,把它们放在地上的地方撒盐,然后买一台全新的电脑,把所有的东西都试一遍。

到目前为止,没有任何效果。当我在http://louistiao.me/posts/notebooks/embedding-matplotlib-animations-in-jupyter-as-interactive-javascript-widgets/ 运行示例代码时,我可以让它工作,只使用他们的代码。

但我无法让自己的代码工作。任何帮助将非常感激。谢谢!

【问题讨论】:

    标签: python-3.x matplotlib animation jupyter-notebook matplotlib-animation


    【解决方案1】:

    我不知道你是否尝试过这个,但对我来说,当我在调用 HTML 之前设置一个变量时它起作用了:

    from IPython.display import HTML
    html = anim.to_html5_video()
    HTML(html)
    

    【讨论】:

      【解决方案2】:
      plt.rcParams['animation.ffmpeg_path'] = 'C:\FFmpeg\ffmpeg-20200610-9dfb19b-win64-static\bin\ffmpeg.exe'
      

      这里你要在'C:~~~'前面加上r作为r'C:~~~'

      plt.rcParams['animation.ffmpeg_path'] = r'C:\FFmpeg\ffmpeg-20200610-9dfb19b-win64-static\bin\ffmpeg.exe'
      

      【讨论】:

        猜你喜欢
        • 2020-10-23
        • 1970-01-01
        • 2019-08-14
        • 2020-05-18
        • 2021-01-29
        • 1970-01-01
        • 2015-09-20
        • 2014-05-29
        • 2018-06-05
        相关资源
        最近更新 更多