无法正确安装 Librosa(sndfile.dll 没有名为 'sf_wchar_open' 的属性)
Trouble installing Librosa properly (sndfile.dll has not attribute named 'sf_wchar_open')
我正在尝试在 Anaconda 环境中安装 librosa,我创建了一个全新的并安装了 librosa,但是我一直遇到这个问题,即使我重新安装 cffi 包、audioread 和其他包。我不确定如何解决这个问题。
AttributeError Traceback (most recent call last)
<ipython-input-4-d10be33b41bf> in <module>
1 # load files with librosa as a series of floating points
----> 2 debussy, sr = librosa.load(debussy_file)
~\.conda\envs\librosa\lib\site-packages\librosa\core\audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
144
145 try:
--> 146 with sf.SoundFile(path) as sf_desc:
147 sr_native = sf_desc.samplerate
148 if offset:
~\.conda\envs\librosa\lib\site-packages\soundfile.py in __init__(self, file, mode, samplerate, channels, subtype, endian, format, closefd)
625 self._info = _create_info_struct(file, mode, samplerate, channels,
626 format, subtype, endian)
--> 627 self._file = self._open(file, mode_int, closefd)
628 if set(mode).issuperset('r+') and self.seekable():
629 # Move write position to 0 (like in Python file objects)
~\.conda\envs\librosa\lib\site-packages\soundfile.py in _open(self, file, mode_int, closefd)
1168 if isinstance(file, _unicode):
1169 if _sys.platform == 'win32':
-> 1170 openfunction = _snd.sf_wchar_open
1171 else:
1172 file = file.encode(_sys.getfilesystemencoding())
AttributeError: cffi library 'C:\Users\User\.conda\envs\librosa\Library\bin\sndfile.dll' has no function, constant or global variable named 'sf_wchar_open'
我不知道真正的解决方法,但是从 soundfile.py
中删除该代码为我解决了这个问题。
只需删除第1170行的if
循环,修改为:
if isinstance(file, _unicode):
file = file.encode(_sys.getfilesystemencoding())
错误不再发生。我正在找人解释原因和方法,但就目前而言,这很有效!
conda-forge 的 libsndfile 1.0.29 似乎已于 2020 年 11 月 5 日损坏。在修复之前,GitHub 上发布的“解决方案”是 1 ) 使用 pip 安装 librosa,或 2) 在 conda 中,删除 libsndfile 并从 pip 安装声音文件。
我正在尝试在 Anaconda 环境中安装 librosa,我创建了一个全新的并安装了 librosa,但是我一直遇到这个问题,即使我重新安装 cffi 包、audioread 和其他包。我不确定如何解决这个问题。
AttributeError Traceback (most recent call last)
<ipython-input-4-d10be33b41bf> in <module>
1 # load files with librosa as a series of floating points
----> 2 debussy, sr = librosa.load(debussy_file)
~\.conda\envs\librosa\lib\site-packages\librosa\core\audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
144
145 try:
--> 146 with sf.SoundFile(path) as sf_desc:
147 sr_native = sf_desc.samplerate
148 if offset:
~\.conda\envs\librosa\lib\site-packages\soundfile.py in __init__(self, file, mode, samplerate, channels, subtype, endian, format, closefd)
625 self._info = _create_info_struct(file, mode, samplerate, channels,
626 format, subtype, endian)
--> 627 self._file = self._open(file, mode_int, closefd)
628 if set(mode).issuperset('r+') and self.seekable():
629 # Move write position to 0 (like in Python file objects)
~\.conda\envs\librosa\lib\site-packages\soundfile.py in _open(self, file, mode_int, closefd)
1168 if isinstance(file, _unicode):
1169 if _sys.platform == 'win32':
-> 1170 openfunction = _snd.sf_wchar_open
1171 else:
1172 file = file.encode(_sys.getfilesystemencoding())
AttributeError: cffi library 'C:\Users\User\.conda\envs\librosa\Library\bin\sndfile.dll' has no function, constant or global variable named 'sf_wchar_open'
我不知道真正的解决方法,但是从 soundfile.py
中删除该代码为我解决了这个问题。
只需删除第1170行的if
循环,修改为:
if isinstance(file, _unicode):
file = file.encode(_sys.getfilesystemencoding())
错误不再发生。我正在找人解释原因和方法,但就目前而言,这很有效!
conda-forge 的 libsndfile 1.0.29 似乎已于 2020 年 11 月 5 日损坏。在修复之前,GitHub 上发布的“解决方案”是 1 ) 使用 pip 安装 librosa,或 2) 在 conda 中,删除 libsndfile 并从 pip 安装声音文件。