トップ 最新 追記

役に立たない情報


2021年10月26日 [mac][python] PyAudioをインストールした時の話

_ [mac][python] PyAudioをインストールしようとしたらエラーがたくさん出る

最近流行ってるじゃん?機械学習だAIだディープニューラルネットワークだフェデレーテッドラーニングだ,と.で,なんでかよくわからないけど流れで音声解析することになってmacで環境作ろうとしたら,ふむなるほどとりあえずPyAudioをインストールしてみっか,ってなったらエラーがうわーってでてくる. 具体的にはこんな感じ.

% pip install pyaudio
Collecting pyaudio
  Using cached PyAudio-0.2.11.tar.gz (37 kB)
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/kido/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-install-rr2nf4mo/pyaudio/setup.py'"'"'; __file__='"'"'/private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-install-rr2nf4mo/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 /private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-wheel-83vkx2lv
       cwd: /private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-install-rr2nf4mo/pyaudio/
  Complete output (16 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.9-x86_64-3.8
  copying src/pyaudio.py -> build/lib.macosx-10.9-x86_64-3.8
  running build_ext
  building '_portaudio' extension
  creating build/temp.macosx-10.9-x86_64-3.8
  creating build/temp.macosx-10.9-x86_64-3.8/src
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/kido/anaconda3/include -arch x86_64 -I/Users/kido/anaconda3/include -arch x86_64 -DMACOSX=1 -I/Users/kido/anaconda3/include/python3.8 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-x86_64-3.8/src/_portaudiomodule.o
  src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
  #include "portaudio.h"
           ^~~~~~~~~~~~~
  1 error generated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for pyaudio
  Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
    Running setup.py install for pyaudio ... error
    ERROR: Command errored out with exit status 1:
    command: /Users/kido/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-install-rr2nf4mo/pyaudio/setup.py'"'"'; __file__='"'"'/private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-install-rr2nf4mo/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-record-q9fjahjy/install-record.txt --single-version-externally-managed --compile --install-headers /Users/kido/anaconda3/include/python3.8/pyaudio
         cwd: /private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-install-rr2nf4mo/pyaudio/
    Complete output (16 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.8
    copying src/pyaudio.py -> build/lib.macosx-10.9-x86_64-3.8
    running build_ext
    building '_portaudio' extension
    creating build/temp.macosx-10.9-x86_64-3.8
    creating build/temp.macosx-10.9-x86_64-3.8/src
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/kido/anaconda3/include -arch x86_64 -I/Users/kido/anaconda3/include -arch x86_64 -DMACOSX=1 -I/Users/kido/anaconda3/include/python3.8 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-x86_64-3.8/src/_portaudiomodule.o
    src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
    #include "portaudio.h"
             ^~~~~~~~~~~~~
    1 error generated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/kido/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-install-rr2nf4mo/pyaudio/setup.py'"'"'; __file__='"'"'/private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-install-rr2nf4mo/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/pv/yknnpbz533vfgwpd1ygkdjk80000gn/T/pip-record-q9fjahjy/install-record.txt --single-version-externally-managed --compile --install-headers /Users/kido/anaconda3/include/python3.8/pyaudio Check the logs for full command output.
%

まあようするにportaudioをインストールしろよってのと,portaudio.hが見つかってねえこのぼんくらっていうエラーメッセージなのね. そうですかportaudioを入れればいいのね?

% brew install portaudio

ってするとあっさりportaudioは入る.だから

% pip install pyaudio

って続けて打つとまた同じエラー..

とりあえずportaudioがインストールしたportaudio.hを見つけて,そのリンク先ライブラリも指定するかってなって

% sudo env LDFLAGS="-L/opt/homebrew/Cellar/portaudio/19.7.0/lib" CFLAGS="-I/opt/homebrew/Cellar/portaudio/19.7.0/include" pip install pyaudio
WARNING: The directory '/Users/kido/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache 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.11.tar.gz (37 kB)
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (setup.py) ... done
  Created wheel for pyaudio: filename=PyAudio-0.2.11-cp38-cp38-macosx_10_9_x86_64.whl size=23395 sha256=036d69d59371d4c0de2b7f8b99958ab5f59e382be1df098287330ed5779f28a2
  Stored in directory: /private/tmp/pip-ephem-wheel-cache-lc1upr5l/wheels/cf/be/f6/06f4d9fb96713a3ba58a480dd5739b3bf66ff0430de58a38c1
Successfully built pyaudio
Installing collected packages: pyaudio
Successfully installed pyaudio-0.2.11
%

とするとちゃんとインストールできたよ!じゃあね!