按照如何在 Python 中创建动画图形 在构建动画图时,在编写 ffmpeg 时,我收到以下错误:
'Requested MovieWriter ({}) not available'.format(name))
RuntimeError: Requested MovieWriter (ffmpeg) not available
收到此错误后,我最初尝试使用以下方法使用 pip
安装 ffmpeg:
python -m install ffmpeg
它似乎已成功安装 ffmpeg,但回到我的代码,我仍然收到相同的错误
在下面找到我的代码:
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.animation as animation
overdoses = pd.read_excel(r'C:UsersACERDesktopoverdose_data_1999-2015.xls',sheet_name='Online',skiprows =6)
def get_data(table,rownum,title):
data = pd.DataFrame(table.loc[rownum][2:]).astype(float)
data.columns = {title}
return data
title = 'Heroin Overdoses'
d = get_data(overdoses,18,title)
x = np.array(d.index)
y = np.array(d['Heroin Overdoses'])
overdose = pd.DataFrame(y,x)
overdose.columns = {title}
Writer = animation.writers['ffmpeg']
下面是堆栈跟踪:
Traceback (most recent call last):
File "C:PythonPython36libsite-packagesmatplotlibanimation.py", line 161, in __getitem__
return self.avail[name]
KeyError: 'ffmpeg'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
Writer = animation.writers['ffmpeg']
File "C:PythonPython36libsite-packagesmatplotlibanimation.py", line 164, in __getitem__
'Requested MovieWriter ({}) not available'.format(name))
RuntimeError: Requested MovieWriter (ffmpeg) not available
显然,您尚未安装ffmpeg
(正确(。在安装过程中几乎看起来是一个权限问题?尝试卸载/清理ffmpeg
并进行适当的重新安装。
我看到您正在尝试遵循"如何在 Python 中创建动画图形"。为什么不干脆跳过ffmpeg
部分,最后做一个plt.show()
来观看动画。