Pydub from_mp3 给出 [Errno 2] No such file or directory
Pydub from_mp3 gives [Errno 2] No such file or directory
我发现自己在墙前,只是试图将音频文件加载到 pydub 中进行转换,它不断抛出“[Errno 2] 没有这样的文件或目录”错误。
当然我花了太多时间来确保路径有效,尝试了相对和绝对路径并确认 python 方法 open() 在完全相同的路径下工作正常,它是.
我在 ipython 3.2 和 python 2.7 中工作,通过 ubuntu.
上的 anaconda 2.3 distrib
from pydub import AudioSegment
sound = AudioSegment.from_mp3("/absolute/path/to/file.mp3")
还尝试在路径中不使用空格,因为这有时是个问题。这是完整的错误日志:
---------------------------------------------------------------------------
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
我是对这里非常简单的事情视而不见还是...?
编辑:
正如 Vaulstein 所询问的那样,我还尝试将路径作为原始文本 r/absolute/path/to/file.mp3" 传递 - 这给了我同样的错误。
异常与您提供的文件名无关。查看回溯,找不到 subprocess.Popen
调用的 conversion_command
。这反过来可以解释 avconv
和 ffmpeg
都找不到的警告。解决方案应该是在控制台中为 sudo apt-get install libav-tools
安装 libav-tools 包。
我发现自己在墙前,只是试图将音频文件加载到 pydub 中进行转换,它不断抛出“[Errno 2] 没有这样的文件或目录”错误。
当然我花了太多时间来确保路径有效,尝试了相对和绝对路径并确认 python 方法 open() 在完全相同的路径下工作正常,它是.
我在 ipython 3.2 和 python 2.7 中工作,通过 ubuntu.
上的 anaconda 2.3 distribfrom pydub import AudioSegment
sound = AudioSegment.from_mp3("/absolute/path/to/file.mp3")
还尝试在路径中不使用空格,因为这有时是个问题。这是完整的错误日志:
---------------------------------------------------------------------------
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
我是对这里非常简单的事情视而不见还是...?
编辑: 正如 Vaulstein 所询问的那样,我还尝试将路径作为原始文本 r/absolute/path/to/file.mp3" 传递 - 这给了我同样的错误。
异常与您提供的文件名无关。查看回溯,找不到 subprocess.Popen
调用的 conversion_command
。这反过来可以解释 avconv
和 ffmpeg
都找不到的警告。解决方案应该是在控制台中为 sudo apt-get install libav-tools
安装 libav-tools 包。