You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Anaconda Spyder运行m4a转mp3脚本提示ffprobe不存在求助

m4a转mp3脚本运行报错:找不到ffprobe

操作背景

通过Anaconda Navigator启动Spyder,运行以下.m4a转.mp3的Python脚本:

import os
import pydub
import glob

m4a_files = glob.glob('./*.m4a')

all_files = [m4a_files]

for files in all_files:
    for file in files:
        mp3_file = os.path.splitext(file)[0] + '.mp3'
        sound = pydub.AudioSegment.from_file(file)
        print("Converting: ",file)
        sound.export(mp3_file, format="mp3")
        os.remove(file)
        print("Conversion Complete")

报错信息

运行后抛出如下错误:

runfile('/Users/MyName/Library/CloudStorage/OneDrive-Personal/Bibliothek/Deutsch/Wörterbuch/Soundaufnahmen/Wörterbuch_2000-3000_Original_Non-Equilazed/Converter_1.py', wdir='/Users/MyName/Library/CloudStorage/OneDrive-Personal/Bibliothek/Deutsch/Wörterbuch/Soundaufnahmen/Wörterbuch_2000-3000_Original_Non-Equilazed')
/Users/MyName/anaconda3/lib/python3.11/site-packages/pydub/utils.py:198: RuntimeWarning: Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work
  warn("Couldn't find ffprobe or avprobe - defaulting to ffprobe, but may not work", RuntimeWarning)
Traceback (most recent call last):

  File ~/anaconda3/lib/python3.11/site-packages/spyder_kernels/py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File ~/Library/CloudStorage/OneDrive-Personal/Bibliothek/Deutsch/Wörterbuch/Soundaufnahmen/Wörterbuch_2000-3000_Original_Non-Equilazed/Converter_1.py:26
    sound = pydub.AudioSegment.from_file(file)

  File ~/anaconda3/lib/python3.11/site-packages/pydub/audio_segment.py:728 in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)

  File ~/anaconda3/lib/python3.11/site-packages/pydub/utils.py:274 in mediainfo_json
    res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)

  File ~/anaconda3/lib/python3.11/subprocess.py:1024 in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,

  File ~/anaconda3/lib/python3.11/subprocess.py:1917 in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)

FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe'

已尝试的无效操作

  • 在脚本中添加Python路径:
    sys.path.append('/Users/MyName/anaconda3/lib/python3.11/site-packages')
    sys.path.append('/Users/MyName/anaconda3/lib/python3.11/site-packages/ffprobe')
    
  • 通过Spyder的Tools/PYTHONPATH Manager添加上述两个目录,但目录无法显示在列表中

解决方案

1. 通过conda安装完整ffmpeg套件

pydub依赖的是ffmpeg工具包中的可执行程序,不是Python的ffprobe库。在终端或Anaconda Prompt中运行以下命令安装:

conda install -c conda-forge ffmpeg

安装完成后,ffprobe和ffmpeg可执行文件会自动加入环境变量,pydub能直接调用。

2. 手动指定可执行文件路径(可选)

如果conda安装后仍无法识别,可在脚本开头手动指定ffmpeg和ffprobe的路径(替换为你实际的路径):

import pydub
# 替换为你的conda环境中ffmpeg和ffprobe的实际路径
pydub.AudioSegment.converter = "/Users/MyName/anaconda3/bin/ffmpeg"
pydub.AudioSegment.ffprobe = "/Users/MyName/anaconda3/bin/ffprobe"

可以通过终端命令which ffprobe(Mac/Linux)或where ffprobe(Windows)查询可执行文件的准确位置。

3. 验证环境变量

确保ffprobe所在的目录(比如/Users/MyName/anaconda3/bin)被添加到系统的PATH环境变量中,这样系统才能找到该可执行文件。

内容的提问来源于stack exchange,提问作者neptuniumm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 16:47:17