-1

Every time I run pip install pyaudio I get the following error

pip3 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) ... 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-universal2-cpython-310
      copying src/pyaudio.py -> build/lib.macosx-10.9-universal2-cpython-310
      running build_ext
      building '_portaudio' extension
      creating build/temp.macosx-10.9-universal2-cpython-310
      creating build/temp.macosx-10.9-universal2-cpython-310/src
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DMACOSX=1 -I/usr/local/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-universal2-cpython-310/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/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

I tried pip install, reinstalling port audio, but nothing works, any advice how to tackle this problem?

wkl
  • 77,184
  • 16
  • 165
  • 176
treenera
  • 19
  • 3
  • How did you install the portaudio libraries/headers? You need to tell `pip` where to find them. Do `pip3 install --global-option=build_ext --global-option="-L/path/to/portaudio/library/directory" --global-option="-I/path/to/portaudio/header/directory" install pyaudio` and see if that helps. – wkl Aug 10 '22 at 16:28
  • this doesn't work I tried `pip install --global-option='build_ext' --global-option='-I/opt/homebrew/Cellar/portaudio/19.7.0/include' --global-option='-L/opt/homebrew/Cellar/portaudio/19.7.0/lib' pyaudio `, I can't post the error code since it has to much characters. Could this error occur because I have the "new" m1 max chip – treenera Aug 10 '22 at 17:14

3 Answers3

5

This was tested on an M1 Max, so pyaudio should definitely support the platform.

Since you have portaudio installed from homebrew, do this...

LDFLAGS="-L$(brew --prefix portaudio)/lib" CFLAGS="-I$(brew --prefix portaudio)/include" pip install pyaudio

And hopefully you have it built and installed:

python3 -c "import pyaudio; print(pyaudio.__version__)"
0.2.12
wkl
  • 77,184
  • 16
  • 165
  • 176
0

I am a M1 mac user. There has been overwhelming answers toward this way which hasn't worked for me. when installing pyaudio, pip cannot find portaudio.h in /usr/local/include

But I found @wkl's answer worked for me ! thanks.

Quantum
  • 11
  • 2
0

Yesterday I started a project with a voice assistant, but stumbled on PyAudio :((

I tried a lot of different things, as QUANTUM says, but when I tried what WKL recommends, everything fell into place! Amazing, thank you WKL You saved my nerve cells!

INSTEAD OF THIS: python3 -c "import pyaudio; print(pyaudio.__version__)"

BETTER USE THIS: pip show pyaudio

⚠️ I'm sorry to post here as I'm a new user and can't rate his work for the rating to take effect.

Valerij
  • 1
  • 1