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

后端 未结 6 419
无人共我
无人共我 2020-12-06 13:25

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_mp         


        
相关标签:
6条回答
  • 2020-12-06 13:49

    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?

    0 讨论(0)
  • 2020-12-06 13:52

    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

    0 讨论(0)
  • 2020-12-06 13:53

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

    0 讨论(0)
  • 2020-12-06 14:07

    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
    
    0 讨论(0)
  • 2020-12-06 14:14

    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.

    0 讨论(0)
  • 2020-12-06 14:14

    In newer versions of pydub, you can specify the absolute path to your ffmpeg 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.

    0 讨论(0)
提交回复
热议问题