我發現自己在這裏的牆前,只是試圖加載一個音頻文件到pydub轉換它不斷拋出一個「[Errno 2]沒有這樣的文件或目錄「錯誤。Pydub from_mp3給出[Errno 2]沒有這樣的文件或目錄
當然,我花了太多時間確保路徑是有效的,嘗試過相對路徑和絕對路徑,並確認python方法open()在完全相同的路徑下工作正常。
我正在使用python 2.7通過anaconda 2.3 distrib在Ubuntu上進行ipython 3.2的工作。
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
我是否對這裏真正簡單的事情失明或......?
編輯: 我也試圖通過作爲原始文本r「/absolute/path/to/file.mp3」作爲Vaulstein查詢 - 這給了我相同的錯誤的路徑。
你有沒有試過將'path'作爲原始文本? 'r「/absolute/path/to/file.mp3」',以防萬一它有特殊字符。 – Vaulstein
是的,我有,相對和絕對的,得到相同的錯誤。它具有的最特殊的字符是_和 - 。好點,但會增加它的問題! – LudoC
嘗試從'IDE或python shell'運行下面幾行# 'import pydub sound = pydub.AudioSegment.from_mp3(「/ absolute/path/to/file.mp3」)' – Vaulstein