无法导入声音文件 [英] Can't import soundfile

查看:640
本文介绍了无法导入声音文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Anaconda,并且试图导入声音文件/ pysoundfile。

I'm using Anaconda and I'm trying to import soundfile/pysoundfile.

我通过运行

 conda install -c conda-forge pysoundfile 

,我认为它成功了,因为当我运行

and I think it succeeded because when I run

 conda list 

它显示:

pyopenssl                 17.2.0           py36h5d7bf08_0  
pyparsing                 2.2.0            py36hb281f35_0  
pyqt                      5.6.0            py36he5c6137_6  
pysocks                   1.6.7            py36hfa33cec_1  
pysoundfile               0.10.1           py_0            conda-forge
pytables                  3.4.2            py36hfbd7ab0_2  
pytest                    3.2.1            py36h9963153_1  

为确保运行的是正确的python,我尝试运行

To make sure I'm running the "right" python, I've tried running

which python

我得到

 /anaconda3/bin/python

但是当我打开python并尝试运行

But when I open python and try running

import soundfile 

我得到了以下:

Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/site-packages/soundfile.py", line 142, in <module>
    raise OSError('sndfile library not found')
OSError: sndfile library not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/anaconda3/lib/python3.6/site-packages/soundfile.py", line 163, in <module>
    _path, '_soundfile_data', _libname))
OSError: cannot load library '/anaconda3/lib/python3.6/site-packages/_soundfile_data/libsndfile.dylib': dlopen(/anaconda3/lib/python3.6/site-packages/_soundfile_data/libsndfile.dylib, 2): image not found

Out出于好奇,我使用文本编辑器打开了soundfile.py文件,以查看第142行的样子,如下所示:

Out of curiosity I opened the soundfile.py file with a text editor to see what line 142 looked like, and it looks like this:

try:
    _libname = _find_library('sndfile')
    if _libname is None:
        raise OSError('sndfile library not found')      # <---- line 142
    _snd = _ffi.dlopen(_libname)
except OSError:
    if _sys.platform == 'darwin':
        _libname = 'libsndfile.dylib'
    elif _sys.platform == 'win32':
        from platform import architecture as _architecture
        _libname = 'libsndfile' + _architecture()[0] + '.dll'
    else:
        raise

    # hack for packaging tools like cx_Freeze, which
    # compress all scripts into a zip file
    # which causes __file__ to be inside this zip file

    _path = _os.path.dirname(_os.path.abspath(__file__))

    while not _os.path.isdir(_path):
        _path = _os.path.abspath(_os.path.join(_path, '..'))

    _snd = _ffi.dlopen(_os.path.join(
        _path, '_soundfile_data', _libname))

在文档中,导入声音文件是正确的导入方式,但我也尝试过

In the docs, it says "import soundfile" is the correct way to import, but I also tried

import pysoundfile 

只有

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pysoundfile'

有人知道为什么会这样吗?我正在MacOS btw上运行它。

Is there anyone who knows why this is happening? I'm running this on MacOS btw.

推荐答案

阅读重大更改部分此处

我们将导入名称从import pysoundfile更改为0.7中的导入声音文件。

解决方法

pip install SoundFile

< img src = https://i.stack.imgur.com/ievLM.png alt =在此处输入图片描述>

这篇关于无法导入声音文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆