繁体   English   中英

没有名为 soundfile 的模块

[英]No module named soundfile

每当我尝试导入soundfile我都会收到错误消息

ImportError: No module named soundfile

我安装 pysoundfile 似乎没有问题:

$ sudo pip install pysoundfile
The directory '/Users/theonlygusti/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/theonlygusti/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pysoundfile
  Downloading PySoundFile-0.9.0.post1-py2.py3.cp26.cp27.cp32.cp33.cp34.cp35.cp36.pp27.pp32.pp33-none-macosx_10_5_x86_64.macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.whl (573kB)
    100% |████████████████████████████████| 573kB 430kB/s
Requirement already satisfied: cffi>=0.6 in /Library/Python/2.7/site-packages (from pysoundfile)
Requirement already satisfied: pycparser in /Library/Python/2.7/site-packages (from cffi>=0.6->pysoundfile)
Installing collected packages: pysoundfile
Successfully installed pysoundfile-0.9.0.post1

那么是什么导致了这个问题?

检查是否安装在测试环境中

示例方式

$ pip install virtualenv
$ python -m virtualenv venv
$ source venv/bin/activate
$ pip install pysoundfile
$ python
>>> import soundfile

PySoundFile 依赖于 Python 包 CFFI 和 NumPy,以及系统库 libsndfile。

要安装 Python 依赖项,我建议使用 Python 3 的 Anaconda 发行版。

这将预装所有依赖项。 要手动安装依赖项,您可以使用 conda 包管理器,它将使用conda install cffi numpy安装所有依赖conda install cffi numpyconda install cffi numpy也可以通过pip install conda conda install cffi numpy独立于 Anaconda 使用)。

安装 CFFI 和 NumPy 后,您可以使用pip install pysoundfile下载并安装最新版本的 PySoundFile。 在 Windows 和 OS X 上,这也将安装库 libsndfile。 在 Linux 上,您需要使用发行版的包管理器安装 libsndfile,例如sudo apt-get install libsndfile1

我遇到了同样的问题,我想问题出在 python 版本上。 当我尝试使用Python 3.5.2 时

python3 file_name.py
ImportError: No module named 'soundfile'

相反,我用Python 2.7.12尝试了同样的方法

python file_name.py

它成功导入了它!

对于 Google Colab 研究

复制粘贴这个

!pip install soundfile

&然后导入它

import soundfile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM