无法正确安装Librosasndfile.dll没有名为“ 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,626                                          format,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,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安装声音文件。

https://github.com/bastibe/SoundFile/issues/278

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...