Matplotlib动画错误“请求的MovieWriter(ffmpeg)不可用”

时间:2020-06-12 06:29:57

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

我正在尝试使用matplotlib FuncAnimation运行动画,并且不断遇到错误 “请求的MovieWriter(ffmpeg)不可用”。我知道这个问题以前曾被问过,我已经查看了对此的所有答复,但都没有奏效。

我正在Windows 10上运行jupyter笔记本

我有以下代码。

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:请求的MovieWriter(ffmpeg)不可用

这是我尝试过的。 1)在我的系统上安装ffmpeg,并设置路径值。我按照此处的说明https://www.wikihow.com/Install-FFmpeg-on-Windows 我通过在cmd窗口中键入ffmpeg -version验证是否已安装FFmpeg 2)conda安装-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笔记本中设置了路径变量

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/运行示例代码时,仅使用它们的代码就可以使它工作。

但是我无法获得自己的代码。任何帮助将非常感激。谢谢!

1 个答案:

答案 0 :(得分:0)

我不知道您是否尝试过此方法,但是对我来说,当我在调用HTML之前设置变量时,它就起作用了:

var txt = '{"name":"John", "age":30, "city":"New York"}'
var obj = JSON.parse(txt);
document.getElementById("demo").innerHTML = obj.name + ", " + obj.age;