Pydub from_mp3提供[Errno 2]没有这样的文件或目录 [英] Pydub from_mp3 gives [Errno 2] No such file or directory

查看:150
本文介绍了Pydub from_mp3提供[Errno 2]没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现自己在墙前,只是试图将音频文件加载到pydub中进行转换,这会不断引发"[Errno 2] No such file or directory"错误.

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.

自然,我花了太多时间来确保路径有效,尝试了相对路径和绝对路径,并确认python方法open()在完全相同的路径下可以正常工作.

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.

我正在通过ubuntu上的anaconda 2.3发行版在python 2.7中使用ipython 3.2.

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...?

我还尝试按照Vaulstein的要求将路径作为原始文本r"/absolute/path/to/file.mp3"传递-这给了我同样的错误.

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.

推荐答案

例外与您提供的文件名无关.在回溯中,找不到subprocess.Popen调用的是conversion_command.反过来,这也可以解释以下警告:找不到avconvffmpeg.解决方案应该是在控制台中为sudo apt-get install libav-tools安装 libav-tools 软件包.

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.

这篇关于Pydub from_mp3提供[Errno 2]没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆