如何在Mac上使用Python 3安装pyaudio?

49

我首先尝试了:

pip install pyaudio

但我被告知

-bash: pip: command not found

然后我尝试了:

pip3 install pyaudio

然后我得到了:
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found

#include "portaudio.h"

         ^

1 error generated.

error: command '/usr/bin/clang' failed with exit status 1

----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 -c "import setuptools, tokenize;__file__='/private/var/folders/77/gz1txkwj2z925vk6jrkx3wp80000gn/T/pip-build-43z_qk7o/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/77/gz1txkwj2z925vk6jrkx3wp80000gn/T/pip-tkf78ih4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/77/gz1txkwj2z925vk6jrkx3wp80000gn/T/pip-build-43z_qk7o/pyaudio

但我已经安装了PortAudio

brew install portaudio

警告:portaudio-19.20140130已经安装

那我该怎么办?

11个回答

0
我在macOS Ventura 13.2上遇到了类似的问题。 以下是错误和解决方案,以防其他人遇到类似问题。
错误:
$ pip3 install pyaudio
Collecting pyaudio
  Using cached PyAudio-0.2.13.tar.gz (46 kB)
  ...
  ...
  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
  ╰─> [20 lines of output]
      Error in sitecustomize; set PYTHONVERBOSE for traceback:
      AssertionError:
      running bdist_wheel
      ...
      ...
      src/pyaudio/device_api.c:9: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

解决方案

我只需要做以下操作:

brew install portaudio
pip3 install pyaudio

在虚拟环境中有效吗? - D.Fitz
@D.Fitz - 是的,确实如此。 - Anil_M

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接