[英]Matplotlib animation MovieWriters fails on Ubuntu 12.04
I am attempting to save matplotlib animations to a movie via ffmpeg
on Ubuntu 12.04 LTS (32-bit Desktop). 我试图通过Ubuntu 12.04 LTS(32位桌面)上的
ffmpeg
将matplotlib动画保存到电影中。 Following the matplotlib example , it fails to load the animation writer: AttributeError: 'module' object has no attribute 'writers'
(line 15 of the example): 在matplotlib 示例之后 ,它无法加载动画
AttributeError: 'module' object has no attribute 'writers'
: AttributeError: 'module' object has no attribute 'writers'
(示例的第15行):
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. 通过
apt-get
,我尝试了安装ffmpeg,每个编解码器都可以想象,甚至尝试从源代码编译ffmpeg。 Nothing works. 什么都行不通。
How do I get matplotlib
to talk to ffmpeg on Ubuntu? 如何让
matplotlib
与Ubuntu上的ffmpeg交谈?
If you are using the unbuntu
packaged version of matplotlib
it is 1.1.1rc1
. 如果您使用的是
unbuntu
打包版本的matplotlib
那么它是1.1.1rc1
。 The attribute writers
was added about 3 months after that tag, and is in versions 1.2
and later. 属性
writers
在该标记之后大约3个月添加,并且在版本1.2
及更高版本中。
You can either install matplotlib
from source (this is what I do, it's not too bad) or use the daily ppa . 您可以从源代码安装
matplotlib
(这是我做的,它不是太糟糕)或使用每日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 我从源代码编译的建议是尽可能多地使用打包系统并手动安装
matplotlib
(如果你想使用pip, 请参阅这个答案 )
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 (它将为您提供最新的稳定版本)然后确保它安装的路径在您的
$PYTHONPATH
,可以通过包含该行来完成
export PYTHONPATH=/home/username/local_installs/lib/python2.7/site-packages/:$PYTHONPATH
in your ~/.bashrc
file. 在你的
~/.bashrc
文件中。 You might have to vary that line a bit depending on which version of python you use. 根据您使用的python版本,您可能需要稍微改变一下这一行。 You might need to do this (and make sure folders exist) before
setup.py
will be happy. 您可能需要在
setup.py
满意之前执行此操作(并确保文件夹存在)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.