32
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

macOSにpyaudioをインストールする

Posted at

イントロダクション

PyAudioはクロスプラットフォームのオーディオI/Oライブラリ「PortAudio」に対するPython用のバインディングです。Google Cloud Speech APIをはじめ、Pythonでサンプルが提供されている音声認識ライブラリなどを実行する際には必須のライブラリですが、HomebrewでPortAudioをインストールした環境において、PyAudioのインストール中に失敗することがあります。以下、その問題に対する解決法を紹介します。

問題

まだPortAudioをまだインストールしていない場合には以下のようにしてインストールします。

$ brew install portaudio
Warning: You are using OS X 10.12.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
==> Downloading http://www.portaudio.com/archives/pa_stable_v19_20140130.tgz
Already downloaded: /Library/Caches/Homebrew/portaudio-19.20140130.tgz
==> ./configure --prefix=/usr/local/Cellar/portaudio/19.20140130 --enable-mac-un
==> make install
🍺  /usr/local/Cellar/portaudio/19.20140130: 32 files, 449.3K, built in 54 seconds

次に、pyaudioをインストールします。しかしながら、この時portaudio.hがみつからないとうエラーでインストールに失敗することがあります。

$ pip install pyaudio
Collecting pyaudio
  Using cached PyAudio-0.2.10.tar.gz
Building wheels for collected packages: pyaudio
  Running setup.py bdist_wheel for pyaudio ... error
  Complete output from command /Users/mayfair/Documents/development/python-docs-samples/speech/grpc/env/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/private/var/folders/1n/gqy2kcyn1j95_cb2vjxr3l2w0000gn/T/pip-build-iwktd6rr/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /var/folders/1n/gqy2kcyn1j95_cb2vjxr3l2w0000gn/T/tmpq4e0nbhhpip-wheel- --python-tag cp35:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.11-x86_64-3.5
  copying src/pyaudio.py -> build/lib.macosx-10.11-x86_64-3.5
  running build_ext
  building '_portaudio' extension
  creating build/temp.macosx-10.11-x86_64-3.5
  creating build/temp.macosx-10.11-x86_64-3.5/src
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DMACOSX=1 -I/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c src/_portaudiomodule.c -o build/temp.macosx-10.11-x86_64-3.5/src/_portaudiomodule.o
  src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
  #include "portaudio.h"
           ^
  1 error generated.
  error: command 'clang' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for pyaudio
(以下略)

解決法

以下のようにしてbrewでインストールされたライブラリ及びインクルードファイルの位置を指定した上でpip install pyaudioを実行します。これにより、無事にpyaudioがインストールできるようになります。

$ sudo env LDFLAGS="-L/usr/local/lib" CFLAGS="-I/usr/local/include" pip install pyaudio
Password:
The directory '/Users/mayfair/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/mayfair/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 pyaudio
  Downloading PyAudio-0.2.10.tar.gz (287kB)
    100% |████████████████████████████████| 296kB 2.0MB/s 
Installing collected packages: pyaudio
  Running setup.py install for pyaudio ... done
Successfully installed pyaudio-0.2.10
32
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
32
25

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?