LoginSignup
10
5

More than 5 years have passed since last update.

Homebrew部 Python3にPyaudio導入の裏技

Last updated at Posted at 2017-05-22

もう語録無視します。

概要

  • Homebrewでスッキリ(管理)したい。
  • なんだかOpenCV3も使いたい気分だし、画像と音声の取り扱いをPython3でしたいなって人向け。
  • Homebrew及びpython3導入について先駆者兄貴にお任せします。
  • macOS Sierra 10.12.4
  • HOMEBREW_VERSION: 1.2.1
  • pip 9.0.1

pip3でpyaudioを挿れる

もうこれが言いたいだけなんです。アホくさ。
以下のコマンド入力してください。

pip3 install pyaudio
実行画面
~$pip3 install pyaudio
Collecting pyaudio
Installing collected packages: pyaudio
Successfully installed pyaudio-0.2.11

じゃけん、対話モードでimportしてみましょうね。

実行画面
~$python3

:relaxed:

実行画面
>>> import pyaudio
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/pyaudio.py", line 116, in <module>
    import _portaudio as pa
ImportError: dlopen(/usr/local/lib/python3.6/site-packages/_portaudio.cpython-36m-darwin.so, 2): Library not loaded: /usr/local/opt/portaudio/lib/libportaudio.2.dylib
  Referenced from: /usr/local/lib/python3.6/site-packages/_portaudio.cpython-36m-darwin.so
  Reason: image not found

:scream:ファッ!?これだけだとimportエラーが普通に起きて、"port"audio関連と推測できるがファイルがないって怒られるゾ。この問題はpython2でも別の形のエラー文で、pyaudio導入にportaudioのライブラリが不足していると怒られた経験済みの兄貴は多いはずです。

既にportaudioを導入していたらそもそも怒られないので、ここから先は蛇足。
portaudioを導入していない人はhomebrewでportaudioをインストールしましょう。

brew install portaudio
実行画面
~$brew install portaudio
==> Downloading https://homebrew.bintray.com/bottles/portaudio-19.6.0.sierra.bot
Already downloaded: /Users/username/Library/Caches/Homebrew/portaudio-19.6.0.sierra.bottle.tar.gz
==> Pouring portaudio-19.6.0.sierra.bottle.tar.gz
==> Using the sandbox
🍺  /usr/local/Cellar/portaudio/19.6.0: 33 files, 452.7KB

再び対話モードでimport確認。
結果が同じになる安心感の為に一応書いておきます。

実行画面
~$python3
Python 3.6.1 (default, Apr  4 2017, 09:40:21) 
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyaudio
>>> 

:relaxed:

編集後記

 pip3でPython3のライブラリをインストールする事は当たり前なのですが、"Python3 pyaudio"で検索を掛けてもあまりにもapt-getとpython2の話ばかりで、この結論に至るに時間が掛かりました。Homebrew部の皆さんに、このページを捧げます。

10
5
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
10
5