Анимация в Jypiter Notebook на windows

У меня не линукс и после упорного гуглиния не получается запустить анимацию.

#plt.rcParams['animation.ffmpeg_path'] = '/usr/bin/ffmpeg'
plt.rcParams['animation.ffmpeg_path'] ='C:\\Program Files\\ffmpeg  \\bin\\ffmpeg.exe'
! pip install ffmpeg

 

x = np.linspace(0, 2 * np.pi, 100)

# Создадим нужную фигуру
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(111, projection='polar')

ax.set_title('Очень крутой график синуса')
ax.set_ylim([-1, 1])
ax.set_xlim([0, 2 * np.pi])
ax.set_xticks(np.linspace(0, 2 * np.pi, 5), ['0', 'π/2', 'π', '3π/2', ''])
ax.legend()

# Создадим линию, в которую будем класть данные
sinus_line = ax.plot([], [])[0]

# Скопируем код с ссылки выше
# initialization function: plot the background of each frame
def init():
    sinus_line.set_data([], [])
    return (sinus_line,)

# animation function. This is called sequentially
def animate(i):
    y = np.sin(x * i / 10)
    sinus_line.set_data(x, y)
    return (sinus_line,)

# call the animator. blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate, init_func=init,
                               frames=100, interval=20, blit=True)

 

#HTML(anim.to_html5_video())
# FFwriter = animation.FFMpegWriter(fps=30, extra_args=['-vcodec', 'libx264'])
#anim.save('basic_animation.mp4', writer = FFwriter)\

HTML(anim.to_html5_video())

KeyError                                  Traceback (most recent call last)
~\Anaconda3\lib\site-packages\matplotlib\animation.py in __getitem__(self, name)
    160         try:
--> 161             return self.avail[name]
    162         except KeyError:

KeyError: 'ffmpeg'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-64-a0cf571597cf> in <module>
      2 # FFwriter = animation.FFMpegWriter(fps=30, extra_args=['-vcodec', 'libx264'])
      3 #anim.save('basic_animation.mp4', writer = FFwriter)\
----> 4 Writer = animation.writers['ffmpeg']
      5 HTML(anim.to_html5_video())

~\Anaconda3\lib\site-packages\matplotlib\animation.py in __getitem__(self, name)
    162         except KeyError:
    163             raise RuntimeError(
--> 164                 'Requested MovieWriter ({}) not available'.format(name))
    165 
    166 

RuntimeError: Requested MovieWriter (ffmpeg) not available

Ответы (1 шт):

Автор решения: karmik

Путь 'C:\\Program Files\\ffmpeg \\bin\\ffmpeg.exe' выглядит крайне подозрительно. Используйте модуль pathlib для указания путей.

Например:

from pathlib import PureWindowsPath

path = PureWindowsPath('c:/Program Files/ffmpeg/bin/ffmpeg.exe')

print(str(path))
→ Ссылка