简体   繁体   English

FileNotFoundError: [Errno 2] 没有这样的文件或目录: 'ffprobe': 'ffprobe'

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

When running the code snippet, I get the error seen in the title.运行代码片段时,出现标题中的错误。

I have re-installed the package pydub ,and pip3 install ffprobe .我已经重新安装了包pydubpip3 install ffprobe

    from pydub.playback import play
    from pydub import AudioSegment


    def change_volume(file_name, alteration):

        song = AudioSegment.from_mp3(file_name)

        new_song = song + alteration

        new_title = ("_%s") % (file_name)

        new_song.export(new_title, format='mp3')

    change_volume("test_sample.mp3", 3)

The output of the code should be a new mp3 file in the directory with slightly risen volume levels ( test.mp3 --> _test.mp3 ), instead I get the error:代码的输出应该是目录中的一个新的 mp3 文件,音量略有提高( test.mp3 --> _test.mp3 ),而是出现错误:

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

First make sure you have ffprobe installed, which is part of FFmpeg, so actually you need to install ffmpeg.首先确保你安装了ffprobe,它是FFmpeg的一部分,所以实际上你需要安装ffmpeg。 You can do that by following the instructions of one of those two sites.您可以按照这两个站点之一的说明进行操作。

https://ffmpeg.org/download.html https://ffmpeg.org/download.html

https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg

After that you need to add the libary to your system path for python to be able to find and to use it.之后,您需要将 libary 添加到您的系统路径中,以便 python 能够找到并使用它。 That can be done by either actually adding the installation path of FFmpeg to your OS path (How to do that depends on your operating system), or by adding it to the temporary path variable that is used inside of python.这可以通过将 FFmpeg 的安装路径实际添加到您的操作系统路径(如何执行取决于您的操作系统)或将其添加到 python 内部使用的临时路径变量来完成。

import sys
sys.path.append('/path/to/ffmpeg')

For the second option you have to make sure to append the path to FFmpeg before importing anything else.对于第二个选项,您必须确保在导入其他任何内容之前将路径附加到 FFmpeg。 This is the better option if you have no option to change the configuration of the root system, but can become very inconsistent when used by different python scripts.如果您没有更改根系统配置的选项,这是更好的选择,但是当被不同的 python 脚本使用时可能会变得非常不一致。

Finally make sure to have ffprobe installed (eg with pip install ffprobe inside a terminal, see https://pypi.org/project/ffprobe ) so that import ffprobe should work inside the python environment.最后,确认已经ffprobe安装(例如使用pip install ffprobe内的终端,见https://pypi.org/project/ffprobe ),使import ffprobe应该Python环境内工作。

I tried the following method, and it worked:我尝试了以下方法,它奏效了:

$ sudo apt update
$ sudo apt install ffmpeg

(I'm on a Mac, using Anaconda3.) (我在 Mac 上,使用 Anaconda3。)

Everyone keeps saying add ffmpeg or ffprobe to your path, but to be clear this means add the executable file to your path (not the directory, not the .py file, or anything else).每个人都一直说将 ffmpeg 或 ffprobe 添加到您的路径,但要清楚这意味着将可执行文件添加到您的路径(不是目录,不是 .py 文件或其他任何文件)。 For some reason, even after pip installing/updating and installing/updating via homebrew both ffmpeg and ffprobe, there were no executable files on my system for either.出于某种原因,即使在通过自制软件 ffmpeg 和 ffprobe pip 安装/更新和安装/更新之后,我的系统上也没有任何可执行文件。 This seems odd;这看起来很奇怪; I have no idea why this might be, but here's how I got it to work:我不知道为什么会这样,但这是我如何让它工作的:

  1. Go to https://ffbinaries.com/downloads and download the zips of both ffmpeg and ffprobe for your system.转到https://ffbinaries.com/downloads并为您的系统下载 ffmpeg 和 ffprobe 的 zip。
  2. Unzip the files to get the executable files.解压缩文件以获取可执行文件。
  3. Move the executable files to the correct path, which for me was "usr/anaconda3/bin" (this directory primarily has executable files).将可执行文件移动到正确的路径,对我来说是“usr/anaconda3/bin”(这个目录主要有可执行文件)。 As others have said, you can check your path using import os;正如其他人所说,您可以使用 import os 检查您的路径; print(os.environ['PATH']).打印(os.environ['PATH'])。
  4. Manually open each of those two executable files from Finder, just so you can give permission to open the file from an unknown developer (ie from the ffbinaries site).从 Finder 手动打开这两个可执行文件中的每一个,这样您就可以授予从未知开发人员(即来自 ffbinaries 站点)打开文件的权限。

That's what finally did it for me, anyway.无论如何,这就是最终为我所做的。 Hope that helps someone else with the same problem.希望能帮助遇到同样问题的其他人。

您可以尝试使用以下命令 apt-get install -y ffmeg

On my Mac, ffmpeg was installed at /usr/local/bin instead of /usr/bin.在我的 Mac 上,ffmpeg 安装在 /usr/local/bin 而不是 /usr/bin。 I added this function which adds my actual path to ffmpeg to the System PATH while the python app is running.我添加了这个函数,它在 python 应用程序运行时将我到 ffmpeg 的实际路径添加到系统路径。 This allowed pydub to find it.这允许 pydub 找到它。

def add_usr_local_bin():
    ffmpeg_path = "/usr/local/bin"
    os.environ["PATH"] += os.pathsep + ffmpeg_path

我在我的 docker 容器“pip3 install ffmpeg-python”中通过这个 comamnd 安装了 ffmpeg,我也遇到了这个错误,然后我通过 apt-get -> apt-get install ffmpeg 安装它,一切正常

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python FileNotFoundError: [Errno 2] No such file or directory: Synology 上的“ffprobe” - Python FileNotFoundError: [Errno 2] No such file or directory: 'ffprobe' on Synology Errno 2 没有这样的文件或目录:'ffprobe':'ffprobe' - Errno 2 No such file or directory: 'ffprobe': 'ffprobe' FileNotFoundError:没有这样的文件或目录:'ffprobe' FileNotFoundError:没有这样的文件或目录:'ffmpeg' - FileNotFoundError: No such file or directory: 'ffprobe' FileNotFoundError: No such file or directory: 'ffmpeg' Android Chaquopy 没有这样的文件或目录:'ffprobe' - Android Chaquopy No such file or directory: 'ffprobe' FileNotFoundError:[Errno 2]没有这样的文件或目录: - FileNotFoundError: [Errno 2] No such file or directory: FileNotFoundError [Errno 2] 没有这样的文件或目录: - FileNotFoundError [Errno 2] No such file or directory: FileNotFoundError: [Errno 2] 没有这样的文件或目录? - FileNotFoundError: [Errno 2] No such file or directory? FileNotFoundError: [Errno 2] 没有这样的文件或目录,但有一个文件 - FileNotFoundError: [Errno 2] No such file or directory but there is a file FileNotFoundError:[错误2]没有这样的文件或目录,但是文件在那里 - FileNotFoundError: [Errno 2] No such file or directory, But the file is there FileNotFoundError: [Errno 2] 没有这样的文件或目录:'ffmpeg' - FileNotFoundError: [Errno 2] No such file or directory: 'ffmpeg'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM