Pydub (WindowsError: [Error 2] The system can not find the file specified) [duplicate]
Asked Answered
P

9

24

I have a problem with Pydub module running in Windows and Linux. When I try open a mp3 file thus:

from pydub import AudioSegment
sound = AudioSegment.from_mp3("test.mp3")

Console show me the next message:

WindowsError: [Error 2] The system can not find the file specified

But...I have the file (test.mp3) in the same folder that the script, the name is correct.

Why I have this problem? (In Linux, have the same error)

Ploughman answered 9/3, 2014 at 15:57 Comment(4)
It would be convenient if you could translate the error to English language and edit the question.Enhanced
test.mp3 has to be in the directory where you run the script from (import os; print(os.getcwd()) to show it), not from the directory where the script is.Disproof
Error translated (pss). I run the script in the same folder where the sound and script are...and i Have the same errorPloughman
Provide details please. What is the python version? Have you installed ffmpeg.Enhanced
E
18

Make sure that you have ffmpeg http://www.ffmpeg.org/ installed. You can get help from this official page.

Other thing that I can think of is that ffmpeg is installed and is in your path but not in the path of the process using pydub.

If this is the reason for the error, then you can set the absolute path to ffmpeg directly like shown below:

import pydub
pydub.AudioSegment.ffmpeg = "/absolute/path/to/ffmpeg"
sound = AudioSegment.from_mp3("test.mp3")

Give this a try.

Ebonieebonite answered 9/3, 2014 at 16:13 Comment(4)
AudioSegment.ffmpeg doesn't work on newer versions, it seems to be AudioSegment.converter as in the other answer.Metz
It not help... Buy when i copy ffmpeg.exe, ffplay.exe and ffprobe.exe to folder C:\Python39 (that was writing in PATH) it work for meSlurry
Dmitry Dronov, thanks. If tou using venv. Put "ffmpeg.exe, ffplay.exe and ffprobe.exe" to "Scripts" folder in "venv"Outfielder
if still a FileNotFoundError is raised it could help to also set the absolute path to ffprobe.exe by doing: pydub.utils.get_prober_name = lambda: "/absolute/path/to/ffprobe"Iodide
V
21

In jupyter notebook this error could persist since the error is with anaconda environment. You can solve this by installing ffmpeg from conda-forge

Got to anaconda prompt and type:

conda install -c conda-forge ffmpeg
Vitrine answered 10/10, 2019 at 17:4 Comment(0)
E
18

Make sure that you have ffmpeg http://www.ffmpeg.org/ installed. You can get help from this official page.

Other thing that I can think of is that ffmpeg is installed and is in your path but not in the path of the process using pydub.

If this is the reason for the error, then you can set the absolute path to ffmpeg directly like shown below:

import pydub
pydub.AudioSegment.ffmpeg = "/absolute/path/to/ffmpeg"
sound = AudioSegment.from_mp3("test.mp3")

Give this a try.

Ebonieebonite answered 9/3, 2014 at 16:13 Comment(4)
AudioSegment.ffmpeg doesn't work on newer versions, it seems to be AudioSegment.converter as in the other answer.Metz
It not help... Buy when i copy ffmpeg.exe, ffplay.exe and ffprobe.exe to folder C:\Python39 (that was writing in PATH) it work for meSlurry
Dmitry Dronov, thanks. If tou using venv. Put "ffmpeg.exe, ffplay.exe and ffprobe.exe" to "Scripts" folder in "venv"Outfielder
if still a FileNotFoundError is raised it could help to also set the absolute path to ffprobe.exe by doing: pydub.utils.get_prober_name = lambda: "/absolute/path/to/ffprobe"Iodide
M
18

The other way is put ffmpeg.exe,ffplay.exe in the current working directory

Mcbroom answered 28/8, 2019 at 19:15 Comment(3)
Thank you so much. It took me 3 days to debug this trivial buggy/error. I was about to give up on pydub. Thanks for your help.Misestimate
Just in case, here's the link to the ffmpeg package, download the whole package (.zip for windows) and extract the zip file to locate the ffmpeg.exe, ffplay.exe and ffprobe.exe inside the bin folder: github.com/BtbN/FFmpeg-Builds/releasesFellows
I needed to add ffprobe.exe too to avoid the error.Lanceolate
R
15

In newer versions of , you can specify the absolute path to your executable by setting the class attribute converter, e.g.:

from pydub import AudioSegment
AudioSegment.converter = "/usr/local/bin/ffmpeg"

In older versions the class attribute used to be ffmpeg, which is deprecated now.

Rosenfeld answered 22/6, 2014 at 19:5 Comment(1)
Be sure to specify the exakt absolute path of your executable not just the path of the folder where the executable is inside (so on windows for example the path should be something like .../ffmpeg.exe)Iodide
D
3

The solution is quite simple, you have to add ffmpeg.exe, ffprobe.exe and ffplay.exe into your script directory. Download these exe files from the FFMPEG download page and take them from the bin folder

Diffract answered 10/8, 2023 at 19:9 Comment(0)
E
2

Solution for MacOs and compiled Python

Maybe this solution is a bit hacky and not the best way, but it actually works for me on MacOs where I had the same problem. It solves the problem if the python script cannot access the system $PATH variable. I had to do it this way because I run my python code as a compiled binary from a java program which means for some reasons that the system $PATH variable set on my MacOs system cannot be accessed by the compiled python code.

Add this to your python code:

import os
os.environ["PATH"] += os.pathsep + '/usr/local/bin'

'/usr/local/bin' is the default for MacOs - please change it if you installed ffmpeg in a different location.

I got the idea from an answer to that question: how do I modify the system path variable in python script?

Eleni answered 17/7, 2019 at 17:58 Comment(1)
Works on windows as well! ThanksPinkiepinkish
I
2

First you should download ffmpeg
Then you can either change pydub defaults or add ffmpeg directory to environment variable path.

1- Downloading ffmpeg (on windows)

Download ffmpeg from http://www.ffmpeg.org/download.html. Two options are available:

  • gyan.dev
  • BtbN

Download fromBtbN: Download the zip file from this link. Then unzip it in C://ffmpeg (or any other directory, but the relevant changes must be made in the following section)

2- Introducing ffmpeg to the system (on windows)

  • Option1: Change pydub defaults

    from pydub import utils, AudioSegment
    
    
    def get_prober_name():
        return "C://ffmpeg/bin/ffprobe.exe"
    
    
    AudioSegment.converter = "C://ffmpeg/bin/ffmpeg.exe"                  
    utils.get_prober_name = get_prober_name
    sound = AudioSegment.from_mp3("test.mp3")
    
  • Option2: Add ffmpeg to environment variable path

Add C:\ffmpeg\bin to environment variable path and then reboot your computer.

learn how to add to environment variables: link

Inexistent answered 15/8, 2023 at 12:41 Comment(0)
F
1

you need to this:

1- Download and extract libav from Windows binaries provided here. (http://builds.libav.org/windows/)

2- Add the libav /bin folder to your PATH envvar

Furthermore answered 20/1, 2019 at 12:50 Comment(0)
I
-1

Install ffmpeg then add ffmpeg.exe to your environment path, it works fine after that.

Improvvisatore answered 23/5, 2022 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.