3

I am attempting to save matplotlib animations to a movie via ffmpeg on Ubuntu 12.04 LTS (32-bit Desktop). Following the matplotlib example, it fails to load the animation writer: AttributeError: 'module' object has no attribute 'writers' (line 15 of the example):

import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as animation

def update_line(num, data, line):
    line.set_data(data[...,:num])
    return line,

# Set up formatting for the movie files
Writer = animation.writers['ffmpeg']

Via apt-get, I've tried installing ffmpeg, every codec imaginable, and even tried to compile ffmpeg from source. Nothing works.

How do I get matplotlib to talk to ffmpeg on Ubuntu?

ph0t0n
  • 735
  • 1
  • 10
  • 24

1 Answers1

4

If you are using the unbuntu packaged version of matplotlib it is 1.1.1rc1. The attribute writers was added about 3 months after that tag, and is in versions 1.2 and later.

You can either install matplotlib from source (this is what I do, it's not too bad) or use the daily ppa.

My advice for compiling from source is to use the packaging system for as many of the dependencies as possible and install matplotlib by hand (if you do want to use pip see this answer) as such

git clone git://github.com/matplotlib/matplotlib.git
cd matplotlib
git checkout -b v1.2.0
python setup.py install --prefix=/home/username/local_installs/

(which will get you the latest stable version) then make sure the path where it got installed is in your $PYTHONPATH which can be done by including the line

export PYTHONPATH=/home/username/local_installs/lib/python2.7/site-packages/:$PYTHONPATH

in your ~/.bashrc file. You might have to vary that line a bit depending on which version of python you use. You might need to do this (and make sure folders exist) before setup.py will be happy.

Community
  • 1
  • 1
tacaswell
  • 84,579
  • 22
  • 210
  • 199
  • maybe the simplest way to install it is to use pip and a virtualenv. see: http://stackoverflow.com/a/11864996/1301710 – bmu Feb 11 '13 at 06:57
  • @bmu added your link to the main text – tacaswell Feb 11 '13 at 15:36
  • @tcaswell Second time in a week you've helped me out. Thanks! It's funny how obvious the answer is when you read it... I simply didn't consider that the packaged version was not up to date. – ph0t0n Feb 13 '13 at 16:00
  • @jjwebster glad to help. If the answers solved your problem could you possibly accept them (the check symbol on the left)? Selfishly, I get rep, and un-selfishly it helps people in the future that have the same question as you know that you found the answer useful. – tacaswell Feb 13 '13 at 16:35
  • @tcaswell You got it. I didn't know the "check" was where the rep came from... I thought it was the up-vote (which I can't do until I get to 15 rep of my own...) – ph0t0n Feb 13 '13 at 17:43
  • @jjwebster rep comes from both. You also get 2 rep for accepting an answer. See http://stackoverflow.com/faq#reputation – tacaswell Feb 13 '13 at 17:48