7

I find myself in front of a wall here, simply trying to load an audio file into pydub for converting it keeps on throwing a "[Errno 2] No such file or directory" error.

Naturally I have spent way too much time making sure the paths were valid, tried relative and absolute paths and confirmed that the python method open() was working fine with the exact same path, which it is.

I'm working in ipython 3.2 with python 2.7 via the anaconda 2.3 distrib on ubuntu.

from pydub import AudioSegment
sound = AudioSegment.from_mp3("/absolute/path/to/file.mp3")

Also tried without spaces in the path as it sometimes is an issue. Here's the full error log:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-15-8b1ec013ca8e> in <module>()
      1 import pydub
----> 2 sound = pydub.AudioSegment.from_mp3("/absolute/path/to/file.mp3")

/home/ludo/anaconda3/envs/python2/lib/python2.7/site-packages/pydub/audio_segment.pyc in from_mp3(cls, file)
    421     @classmethod
    422     def from_mp3(cls, file):
--> 423         return cls.from_file(file, 'mp3')
    424 
    425     @classmethod

/home/ludo/anaconda3/envs/python2/lib/python2.7/site-packages/pydub/audio_segment.pyc in from_file(cls, file, format, **kwargs)
    404         log_conversion(conversion_command)
    405 
--> 406         p = subprocess.Popen(conversion_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    407         p_out, p_err = p.communicate()
    408 

/home/ludo/anaconda3/envs/python2/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    708                                 p2cread, p2cwrite,
    709                                 c2pread, c2pwrite,
--> 710                                 errread, errwrite)
    711         except Exception:
    712             # Preserve original exception in case os.close raises.

/home/ludo/anaconda3/envs/python2/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
   1333                         raise
   1334                 child_exception = pickle.loads(data)
-> 1335                 raise child_exception
   1336 
   1337 

OSError: [Errno 2] No such file or directory

Am I blind to something really simple here or...?

Edit: I have also tried to pass the path as raw text r"/absolute/path/to/file.mp3" as Vaulstein inquired - which gives me the same error.

4
  • Have you tried passing the path as a raw text? r"/absolute/path/to/file.mp3", just in case it has special characters.
    – Vaulstein
    Dec 10, 2015 at 7:47
  • Yes I have, both with relative and absolute ones, getting the same error. The most special characters it has are _ and -. Good point though, will add it to the question!
    – LudoC
    Dec 10, 2015 at 7:49
  • Try running the below lines from an IDE or python shell import pydub sound = pydub.AudioSegment.from_mp3("/absolute/path/to/file.mp3")
    – Vaulstein
    Dec 10, 2015 at 8:01
  • Mmmmkay, tried from the python command line in a Kitty session (is that what you meant by IDE or python shell?): 1/ import pydub throws a "RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work" 2/ doing the same as above "from pydub import AudioSegment" results in the same error.
    – LudoC
    Dec 10, 2015 at 8:36

1 Answer 1

8

The exceptions doesn't have anything todo with the filename you provide. Looking at the traceback it's the conversion_command for the subprocess.Popen call which can't be found. This in turn may explain the warning that neither avconv nor ffmpeg could be found. The solution should be installing the libav-tools package for with sudo apt-get install libav-tools in a console.

3
  • 1
    I believe you're correct - this is one of the most common issues with pydub (and it's why we added the RuntimeWarning)
    – Jiaaro
    Dec 10, 2015 at 17:10
  • 3
    Another note, if ffmpeg/avlib is not in your PATH you can also specify it's location manually like AudioSegment.converter = "/path/to/ffmpeg" before you instantiate any AudioSegment objects :)
    – Jiaaro
    Dec 10, 2015 at 17:13
  • Thanks a lot BlackJack & @Jiaaro - I managed to get it to work from the python command line following your tips, however I still meet the very same error from my ipython notebook. Are you familiar with it? Any idea where it could come from? While my ~/bin is in my path, I did try adding ffmpeg's direct path to the AudioSegment.converter from my notebook.
    – LudoC
    Dec 11, 2015 at 4:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.