记一次Python matplotlib使用ffmpeg和imagemagick错误

问题出现

朋友找我画一个摆线图,手工画起来抓急,于是求助于程序,想把绘制动画表达出来发给朋友,用ffmpeg和imagemagick分别存储视频和动图格式,结果出现如下两种错误:

MovieWriter ffmpeg unavailable; using Pillow instead

MovieWriter imagemagick unavailable; using Pillow instead.

分别提示找不到ffmpge和imagemagick程序。

问题解决

按照缺啥补啥的原则,分别下载ffmpeg和imagemagick两个程序,并解压到特定的目录,我分别从如下两个地方下载:

ffmpeg二进制文件

https://github.com/GyanD/codexffmpeg/releases

imagemagick二进制文件

https://imagemagick.org/script/download.php

这时候,我们可以把本地存储路径加入到环境变量path中,也可以在我们的程序里显式配置(我选择了后者,我的系统环境是Windows),代码如下:

python 复制代码
# 配置ffmpeg路径
plt.rcParams['animation.ffmpeg_path'] = r'J:\software\ffmpeg-7.0.1-full_build\bin\ffmpeg.exe'
# 通过convert_path设置ImageMagick路径
plt.rcParams['animation.convert_path'] = r'J:\software\ImageMagick-7.1.1-33-portable-Q16-x64\convert.exe'

至此,问题解决。

相关推荐
开开心心就好17 分钟前
图片格式转换工具,右键菜单一键转换简化
linux·运维·服务器·python·django·pdf·1024程序员节
骥龙17 分钟前
1.2下、工欲善其事:物联网安全研究环境搭建指南
python·物联网·安全
Lxinccode39 分钟前
BUG(20) : response.text耗时很久, linux耗时十几秒, Windows耗时零点几秒
python·bug·requests·response.text·response.text慢
智航GIS43 分钟前
11.2 Matplotlib 数据可视化教程
python·信息可视化·matplotlib
技术净胜1 小时前
Python 操作 Cookie 完全指南,爬虫与 Web 开发实战
前端·爬虫·python
海棠AI实验室1 小时前
第六章 日志体系:logging 让排错效率翻倍
python·logging
laufing1 小时前
flask_restx 创建restful api
python·flask·restful
毕设源码-郭学长2 小时前
【开题答辩全过程】以 基于python电商商城系统为例,包含答辩的问题和答案
开发语言·python
black0moonlight2 小时前
win11 isaacsim 5.1.0 和lab配置
python