首页 > 解决方案 > 我无法在 M1 mac 上安装 pyaudio

问题描述

我尝试在默认终端和 M1 mac 上的 Visual Studio 代码中安装 PyAudio,运行 python 3.8、macOS 11.2.1 BigSur,这是我得到的错误:

 MacBook-Pro-Jakubik:~ kuba$ pip3 install pyaudio
Collecting pyaudio
  Using cached PyAudio-0.2.11.tar.gz (37 kB)
Using legacy setup.py install for pyaudio, since package 'wheel' is not installed.
Installing collected packages: pyaudio
    Running setup.py install for pyaudio ... error
    ERROR: Command errored out with exit status 1:
     command: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/8h/c3rxt5m1367cq61wy64pl67c0000gp/T/pip-install-yzoe7_ph/pyaudio/setup.py'"'"'; __file__='"'"'/private/var/folders/8h/c3rxt5m1367cq61wy64pl67c0000gp/T/pip-install-yzoe7_ph/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/8h/c3rxt5m1367cq61wy64pl67c0000gp/T/pip-record-jzsqhn9q/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pyaudio
         cwd: /private/var/folders/8h/c3rxt5m1367cq61wy64pl67c0000gp/T/pip-install-yzoe7_ph/pyaudio/
    Complete output (16 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.7
    copying src/pyaudio.py -> build/lib.macosx-10.9-x86_64-3.7
    running build_ext
    building '_portaudio' extension
    creating build/temp.macosx-10.9-x86_64-3.7
    creating build/temp.macosx-10.9-x86_64-3.7/src
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DMACOSX=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c src/_portaudiomodule.c -o build/temp.macosx-10.9-x86_64-3.7/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: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/8h/c3rxt5m1367cq61wy64pl67c0000gp/T/pip-install-yzoe7_ph/pyaudio/setup.py'"'"';__file__='"'"'/private/var/folders/8h/c3rxt5m1367cq61wy64pl67c0000gp/T/pip-install-yzoe7_ph/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/8h/c3rxt5m1367cq61wy64pl67c0000gp/T/pip-record-jzsqhn9q/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m/pyaudio Check the logs for full command output.

标签: python-3.xmacospyaudiomacos-big-surapple-m1

解决方案


pyaudio 需要portaudio库。使用homebrew安装它可能是最简单的(假设它已被移植到 M1 架构)。


推荐阅读