文章目录
- 前言
- 1. 问题描述
- 2. 问题原因
- 4. 解决方法
- 结束语
前言
本篇博客主要解决在win10上使用gym的Monitor监控器保存训练游戏的视频时出现的错误:gym.error.DependencyNotInstalled: Found neither the ffmpeg nor avconv executables.
# 部分代码
env = gym.make("CartPole-v0")
# save
env = gym.wrappers.Monitor(env, directory="monitor-mp4", force=True)
obs_size = env.observation_space.shape[0]
n_actions = env.action_space.n
...
1. 问题描述
在win10上使用gym的Monitor监控器保存训练游戏的视频时出现了错误:gym.error.DependencyNotInstalled: Found neither the ffmpeg nor avconv executables. On OS X, you can install ffmpeg via 'brew install ffmpeg'. On most Ubuntu variants, 'sudo apt-get install ffmpeg' should do it. On Ubuntu 14.04, however, you'll need to install avconv with 'sudo apt-get install libav-tools'.
2. 问题原因
问题出现的原因显而易见,缺少依赖库ffmpeg,然后上来就是pip大法:pip install ffmpeg,当然,这是一个明智的做法,然而安装完之后一运行,还是这个错误。可能有的小伙伴就卖萌了,然后百度搜索一番,找到一个方法:更改参数。
env = gym.wrappers.Monitor(env, directory="monitor-mp4", force=True)
# 更改参数
env = gym.wrappers.Monitor(env, directory="monitor-mp4", video_callable=False, force=True)
# video_callable: False disables video recording
好家伙,上来把我录制视频的操作给我禁用了,这下子异常信息确实“完美”解决了。解决问题嘛,还是要看问题出现的原因,再对症下药。在回过头来仔细看看异常信息提示:Found neither the ffmpeg nor avconv executables意思是没有找到ffmpeg可执行文件,所以还得安装一下ffmpeg。
4. 解决方法
安装ffmpeg可执行文件,注意,我们通过pip安装的ffmpeg并不是一个可执行文件,而是一个ffmpeg的python的API。
对于OS X或者Ubuntu系统,在异常信息中就给出了如何安装ffmpeg的方法,但是没有给出win10上的安装方法,所以需要去官网自行下载。在FFmpeg的官网我们找到了win10系统的安装包。


下载到的安装包是一个编译好的可执行文件,解压后需要将其添加到环境变量PATH中:

然后重启电脑或PyCharm使其生效,再次运行即可生成训练过程中的视频文件及相关模型的信息文件:

OpenAI-gym-video
结束语

继续搬砖…
最后
以上就是苗条彩虹最近收集整理的关于解决使用Monitor出现gym.error.DependencyNotInstalled: Found neither the ffmpeg nor avconv executables的问题的全部内容,更多相关解决使用Monitor出现gym.error.DependencyNotInstalled:内容请搜索靠谱客的其他文章。
发表评论 取消回复