You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS Ventura安装PyAudio报错:找不到portaudio.h文件

在macOS Ventura上安装PyAudio失败的问题

报错信息

Building wheels for collected packages: pyaudio
  WARNING: Ignoring --global-option when building pyaudio using PEP 517
  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
  ╰─> [16 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-x86_64-cpython-39
      copying src/pyaudio.py -> build/lib.macosx-10.9-x86_64-cpython-39
      running build_ext
      building '_portaudio' extension
      creating build/temp.macosx-10.9-x86_64-cpython-39
      creating build/temp.macosx-10.9-x86_64-cpython-39/src
      gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DMACOSX=1 -I/usr/local/include -I/usr/include -I/Users/myname/PycharmProjects/a/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-x86_64-cpython-39/src/_portaudiomodule.o
      src/_portaudiomodule.c:31:10: fatal error: 'portaudio.h' file not found
      #include "portaudio.h"
               ^~~~~~~~~~~~~
      1 error generated.
      error: command '/usr/bin/gcc' 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

已尝试操作

  • 通过brew卸载并重装portaudio,更新所有组件
  • 安装Xcode命令行工具
  • 在Anaconda环境中尝试安装,仍出现相同错误
  • 已安装wheel且依赖满足

疑问

推测系统忽略了全局portaudio,转而寻找其他版本?请问应将portaudio文件放置在何处才能被系统识别?求可行的修复建议。


可行修复方案

方案1:指定PortAudio路径给pip编译

根据Mac芯片类型,直接告诉编译器PortAudio的安装路径:

Intel芯片Mac

pip install pyaudio --no-use-pep517 --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib'

Apple Silicon芯片Mac

pip install pyaudio --no-use-pep517 --global-option='build_ext' --global-option='-I/opt/homebrew/include' --global-option='-L/opt/homebrew/lib'

(加--no-use-pep517是避开PEP 517对全局参数的限制)

方案2:使用预编译包跳过编译

  • 若使用Anaconda环境,直接安装conda预编译版本:
conda install -c conda-forge pyaudio
  • 或用brew直接安装绑定好的PyAudio:
brew install portaudio
brew install pyaudio

方案3:手动复制文件到系统默认搜索目录

如果上述方法无效,手动将PortAudio文件放到编译器默认扫描的位置:

  • 把portaudio.h复制到/usr/local/include目录
  • 把PortAudio的库文件(如libportaudio.dylib)复制到/usr/local/lib目录
    之后再运行pip install pyaudio

内容的提问来源于stack exchange,提问作者Erika

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 10:15:28