没有名为soundfile的模块

时间:2017-08-16 08:32:11

标签: python pip python-2.x

每当我尝试导入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

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

4 个答案:

答案 0 :(得分:2)

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

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

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

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

答案 1 :(得分:1)

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

示例方式

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

答案 2 :(得分:1)

我有同样的问题,我猜问题是python版本。当我尝试使用 Python 3.5.2

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

相反,我尝试使用 Python 2.7.12

python file_name.py

成功导入了它!

答案 3 :(得分:0)

对于Google Colab研究

复制粘贴此

!pip install soundfile

&然后导入

import soundfile