2017-08-16 134 views
1

每當我試圖導入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 

所以什麼導致這個問題呢?

+1

您使用的'python'可執行文件是否與您使用的'pip' executabel相匹配? – Evert

+0

Pip默認安裝python 2.7的安裝包。你用Python 2.7嗎? –

+0

@Evert我在'/ usr/local/bin/python'和'/ usr/local/bin/pip'上都運行了'which'。不知道如何檢查'sudo'是否相同,但運行'sudo which'返回相同。這可能不是正確的診斷方法。 – theonlygusti

回答

0

檢查,如果它被安裝在測試環境中

實例方法

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

PySoundFile依賴於Python包CFFI和NumPy的,並且系統庫libsndfile。

安裝Python依存關係,我建議使用Python 3

的蟒蛇分佈這將與所有依賴預裝。要手動安裝依賴項,您可以使用conda軟件包管理器,它將使用conda install cffi numpy(conda也可獨立於Anaconda並使用pip install conda)安裝所有依賴項。

安裝CFFI和NumPy後,您可以使用pip install pysoundfile下載並安裝最新版本的PySoundFile。在Windows和OS X上,這也將安裝庫libsndfile。在Linux上,您需要使用發行版的軟件包管理器來安裝libsndfile,例如sudo apt-get install libsndfile1

0

我有同樣的問題,我想問題是與python版本。當我試圖Python的3.5.2

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

相反,我試圖用相同的Python 2.7.12

python file_name.py 

它成功導入了!