ModuleNotFoundError: No module named 'ffmpeg' on Spyder although ffmpeg is installed on Anaconda navigator

ModuleNotFoundError: No module named 'ffmpeg' on Spyder although ffmpeg is installed on Anaconda navigator

ffmpeg 安装在 Anaconda Navigator 上(在 base(root) 环境中),但是当我 运行 import ffmpeg 时,我得到这个错误信息:

ModuleNotFoundError: No module named 'ffmpeg'

为什么找不到这个模块,我该如何解决?

我不是专家,但 this thread on GitHub explains that anaconda installs FFmpeg as a script that can be run but not as a package you can import. As such you need to note the path of the FFmpeg.exe for your anaconda environment + build the commands and pass them to the subprocess module, which you do need to import. So, building on a SO questions like ,要压缩视频(例如),python 中的 Windows 命令可能类似于:

import subprocess
pathFFmpeg = r'C:\Users\YOURNAME\anaconda3\envs\ENVNAME\Scripts\ffmpeg.exe'
pathInput = r'C:\Videos\mybigvideo.mp4'
pathOutput = r'C:\Videos\mysmallervideo.mp4'
commands_list = [
    pathFFmpeg,
    "-i", pathInput,
    "-c:v", "libx265",
    "-preset", "fast",
    "-crf", "22",
    "-c:a", "aac",
    "-b:a", "196k",
    "-pix_fmt", "yuv420p", pathOutput
    ]    
results = subprocess.run(commands_list)
if results.returncode==0:
    print ("FFmpeg Script Ran Successfully")
else:
    print ("There was an error running your FFmpeg script")

尝试使用 pip 命令将 FFmpeg 安装为 python 库

pip install ffmpeg

您需要安装ffmpeg-python模块到环境:

pip install ffmpeg-python

conda install -c conda-forge ffmpeg-python

从那里 import ffmpeg 使用环境时的陈述应该有效。