我正在尝试使用 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 安装-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())
但是,这给了我一个无效的格式字符串错误 for 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/ 运行示例代码时我可以让它工作,只使用他们的代码。
但是我无法让我自己的代码工作。任何帮助将非常感激。谢谢!
最佳答案
plt.rcParams['animation.ffmpeg_path'] = 'C:\FFmpeg\ffmpeg-20200610-9dfb19b-win64-static\bin\ffmpeg.exe'
这里要在'C:~~~'前面加r as r'C:~~~'
plt.rcParams['animation.ffmpeg_path'] = r'C:\FFmpeg\ffmpeg-20200610-9dfb19b-win64-static\bin\ffmpeg.exe'
关于python-3.x - Matplotlib动画报错 "Requested MovieWriter (ffmpeg) not available",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62338703/