J.D*_*ren 6 python conda librosa
我正在使用 Anaconda,并且正在尝试导入 soundfile/pysoundfile。
我通过运行安装了该软件包
conda install -c conda-forge pysoundfile
Run Code Online (Sandbox Code Playgroud)
我认为它成功了,因为当我跑步时
conda list
Run Code Online (Sandbox Code Playgroud)
它显示:
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
Run Code Online (Sandbox Code Playgroud)
为了确保我运行“正确的”python,我尝试运行
which python
Run Code Online (Sandbox Code Playgroud)
我得到
/anaconda3/bin/python
Run Code Online (Sandbox Code Playgroud)
但是当我打开 python 并尝试运行时
import soundfile
Run Code Online (Sandbox Code Playgroud)
我得到以下信息:
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
Run Code Online (Sandbox Code Playgroud)
出于好奇,我用文本编辑器打开了 soundfile.py 文件,看看第 142 行是什么样子的,它看起来像这样:
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))
Run Code Online (Sandbox Code Playgroud)
在文档中,它说“导入声音文件”是正确的导入方式,但我也尝试过
import pysoundfile
Run Code Online (Sandbox Code Playgroud)
并且只得到了
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pysoundfile'
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么会发生这种情况?顺便说一句,我正在 MacOS 上运行它。
请阅读此处的重大变更部分
我们在 0.7 中将导入名称从 import pysoundfile 更改为 import soundfile。
解决方法
pip install SoundFile
Run Code Online (Sandbox Code Playgroud)