记一次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'

至此,问题解决。

相关推荐
是上好佳佳佳呀25 分钟前
【数据分析|Day02】Matplotlib 数据可视化笔记
笔记·matplotlib
曲幽7 小时前
FastAPI 身份验证总踩坑?这份 FastAPI Users “避坑指南”请收好
python·fastapi·web·jwt·oauth2·user·authentication
装不满的克莱因瓶7 小时前
掌握 RNN 与 LSTM 模型结构
人工智能·python·rnn·深度学习·神经网络·ai·lstm
何以解忧,唯有..7 小时前
Python包管理工具pip:从入门到精通
开发语言·python·pip
金銀銅鐵8 小时前
用 Tkinter 实现简单的猜数字游戏
后端·python
copyer_xyf8 小时前
Python 模块与包的导入导出
前端·后端·python
ice8130331818 小时前
【Python】Matplotlib折线图绘制
开发语言·python·matplotlib
copyer_xyf8 小时前
Python venv 虚拟环境
前端·后端·python
林爷万福9 小时前
GitHub 开源光谱数据处理项目推荐
python·光纤光谱仪
copyer_xyf10 小时前
Python 如何同时做很多事:进程、线程、协程
前端·后端·python