Pydub from_mp3 gives [Errno 2] No such file or directory

2024/10/10 10:29:24

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     @classmethod422     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                         raise1334                 child_exception = pickle.loads(data)
-> 1335                 raise child_exception1336 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.

Answer

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.

https://en.xdnf.cn/q/69904.html

Related Q&A

Compile Python 3.6.2 on Debian Jessie segfaults on sharedmods

Im trying to compile Python 3.6.2 on a Debian Jessie box with the options./configure --prefix="/opt/python3" \ --enable-optimizations \--with-lto \ --enable-profiling \ --enable-unicode=ucs4 …

Escape space in filepath

Im trying to write a python tool that will read a logfile and process itOne thing it should do is use the paths listed in the logfile (its a logfile for a backup tool)/Volumes/Live_Jobs/Live_Jobs/*SCAN…

How to save web page as text file?

I would like to save a web page (all content) as a text file. (As if you did right click on webpage -> "Save Page As" -> "Save as text file" and not as html file)I have tried …

PIL Image.size returns the opposite width/height

Using PIL to determine width and height of imagesOn a specific image (luckily only this one - but it is troubling) the width/height returning from image.size is the opposite. The image: http://storage.…

Django Rest Framework: Register multiple serializers in ViewSet

Im trying to create a custom API (not using models), but its not showing the request definition in the schema (in consequence, not showing it in swagger). My current code is:views.pyclass InfoViewSet(v…

Which is most accurate way to distinguish one of 8 colors?

Imagine we how some basic colors:RED = Color ((196, 2, 51), "RED") ORANGE = Color ((255, 165, 0), "ORANGE") YELLOW = Color ((255, 205, 0), "YELLOW") GREEN = Color ((0, 128…

Lambda function behavior with and without keyword arguments

I am using lambda functions for GUI programming with tkinter. Recently I got stuck when implementing buttons that open files: self.file="" button = Button(conf_f, text="Tools opt.",…

How to get type annotation within python function scope?

For example: def test():a: intb: strprint(__annotations__) test()This function call raises a NameError: name __annotations__ is not defined error. What I want is to get the type annotation within the f…

General explanation of how epoll works?

Im doing a technical write-up on switching from a database-polling (via synchronous stored procedure call) to a message queue (via pub/sub). Id like to be able to explain how polling a database is vas…

How to return cost, grad as tuple for scipys fmin_cg function

How can I make scipys fmin_cg use one function that returns cost and gradient as a tuple? The problem with having f for cost and fprime for gradient, is that I might have to perform an operation twice…