LoginSignup
6
0

More than 1 year has passed since last update.

pyaudioインストール時、portaudio.h が見つからない

Posted at

M1 mac 特有ではないと思うのですが、 pyaudio をインストールするときに portaudio.h が見つからないというエラーでインストールできなかったので、解決策をメモします。

brew install portaudio

# あらかじめ portaudio.h やライブラリが指定のパスに存在することを確認済み
python -m pip install --global-option='build_ext' --global-option='-I/opt/homebrew/include' --global-option='-L/opt/homebrew/lib' pyaudio

WARNING: Disabling all use of wheels due to the use of --build-option / --global-option / --install-option.
Collecting pyaudio
  Using cached PyAudio-0.2.12.tar.gz (42 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for pyaudio (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [10 lines of output]
      running bdist_wheel
      running build
      running build_py
      running build_ext
      building '_portaudio' extension
      src/_portaudiomodule.c:31:10: fatal error: 'portaudio.h' file not found
      #include "portaudio.h"
               ^~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyaudio
Failed to build pyaudio
ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects

多くの解説がこれでインストールできるとあるのですが、私はできませんでした。

解決策として、 ${HOME}/.pydistutils.cfg に次の3行を定義

[build_ext]
include_dirs=/opt/homebrew/include
library_dirs=/opt/homebrew/lib

この後 pyaudio がインストールできました。

(venv) pip install pyaudio        
Collecting pyaudio
  Using cached PyAudio-0.2.12.tar.gz (42 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (pyproject.toml) ... done
  Created wheel for pyaudio: filename=PyAudio-0.2.12-cp38-cp38-macosx_10_14_arm64.whl size=37717 sha256=.......
  Stored in directory: /Users/xxxxxx/Library/Caches/pip/wheels/......
Successfully built pyaudio
Installing collected packages: pyaudio
Successfully installed pyaudio-0.2.12
6
0
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
6
0