尝试加载Librosa的示例文件时出现文件未找到错误

时间:2019-05-21 01:06:09

标签: python pycharm file-not-found librosa

我正在使用Librosa编写我的第一个程序,所以我从他们的文档中复制了一些代码以查看是否可以运行。尝试加载示例文件时出现文件未找到错误,我不知道为什么。我发现一些人说他们没有后端错误(https://github.com/librosa/librosa/issues/743https://github.com/beetbox/audioread/issues/54),我想知道这是否与我的问题有关?如果使用PyCharm可以有所作为

这是我的代码:

import librosa

filename = librosa.util.example_audio_file()
y, sr = librosa.load(filename)
print(y)

这是错误消息:

Traceback (most recent call last):
  File "C:/Users/owner/PycharmProjects/SongVisualizer/SongVisualizer.py", line 11, in <module>
    y, sr = librosa.load(filename)
  File "C:\Users\owner\PycharmProjects\SongVisualizer\venv\lib\site-packages\librosa\core\audio.py", line 119, in load
    with audioread.audio_open(os.path.realpath(path)) as input_file:
  File "C:\Users\owner\PycharmProjects\SongVisualizer\venv\lib\site-packages\audioread\__init__.py", line 107, in audio_open
    backends = available_backends()
  File "C:\Users\owner\PycharmProjects\SongVisualizer\venv\lib\site-packages\audioread\__init__.py", line 86, in available_backends
    if ffdec.available():
  File "C:\Users\owner\PycharmProjects\SongVisualizer\venv\lib\site-packages\audioread\ffdec.py", line 108, in available
    creationflags=PROC_FLAGS,
  File "C:\Users\owner\PycharmProjects\SongVisualizer\venv\lib\site-packages\audioread\ffdec.py", line 94, in popen_multiple
    return subprocess.Popen(cmd, *args, **kwargs)
  File "C:\Python37\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Python37\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

我遇到同样的问题,并用 return subprocess.Popen(cmd,* args,** kwargs)更改了行 return subprocess.Popen(cmd,* args,** kwargs) ,shell = True)。它可以工作,但是不建议通过外壳执行代码。可以从以下网址找到更多详细信息:Actual meaning of 'shell=True' in subprocess

答案 1 :(得分:0)

我通过安装FFmpeg并将其添加到我的PATH变量中解决了我的问题。 Librosa的音频模块需要FFmpeg来加载和处理音频。