0

I have been trying to install PyAudio for a while. I have installed PortAudio using Homebrew.

I used pip3 install pyaudio and pip install pyaudio to attempt to install but it is throwing an error.

Error:

ERROR: Command errored out with exit status 1:
 command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/z8/0zm6rvc13sq26xhp_lkxqjbm0000gn/T/pip-install-ctufc1pe/pyaudio_f78c4d14ac984d9bbe4ecda8dee42097/setup.py'"'"'; __file__='"'"'/private/var/folders/z8/0zm6rvc13sq26xhp_lkxqjbm0000gn/T/pip-install-ctufc1pe/pyaudio_f78c4d14ac984d9bbe4ecda8dee42097/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' build_ext -I/usr/local/include -L/usr/local/lib install --record /private/var/folders/z8/0zm6rvc13sq26xhp_lkxqjbm0000gn/T/pip-record-tgzbcyw5/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.9/include/python3.9/pyaudio
     cwd: /private/var/folders/z8/0zm6rvc13sq26xhp_lkxqjbm0000gn/T/pip-install-ctufc1pe/pyaudio_f78c4d14ac984d9bbe4ecda8dee42097/
Complete output (11 lines):
running build_ext
building '_portaudio' extension
creating build
creating build/temp.macosx-10.9-x86_64-3.9
creating build/temp.macosx-10.9-x86_64-3.9/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/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-x86_64-3.9/src/_portaudiomodule.o
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
         ^~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/gcc' failed with exit code 1
----------------------------------------

I have even used pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio

I have no idea how to proceed further.

Is there any way to solve this?

Mihir Seth
  • 40
  • 8
  • Is there `/usr/local/include/portaudio.h`? If not you need to fix paths in `-I/usr/local/include…-L/usr/local/lib` – phd Aug 28 '21 at 12:22
  • @phd there is no /usr/local/include. How do I fix this? – Mihir Seth Aug 29 '21 at 10:23
  • `brew install portaudio` installs *somewhere*, I don't know where exactly; I suspect somewhere in `/opt/`. Find out where and use these paths in `pip` command line. Something like `pip install --global-option='build_ext' --global-option='-I/opt/include' --global-option='-L/opt/lib' pyaudio` – phd Aug 29 '21 at 12:17
  • @phd I don't there is a /opt/ file on my laptop. Is there supposed to be one? – Mihir Seth Aug 30 '21 at 09:39
  • It [can be](https://docs.brew.sh/FAQ#why-is-the-default-installation-prefix-opthomebrew-on-apple-silicon) `/opt/homebrew` or `/usr/local`. If both paths are absent try to find over the entire filesystem: `locate -b \\portaudio.h || find / -name portaudio.h` – phd Aug 30 '21 at 10:17
  • @phd I was able to install Pyaudio. However it is now throwing the error. `Could not import the PyAudio C module '_portaudio'. Expected in: flat namespace in /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/_portaudio.cpython-39-darwin.so` – Mihir Seth Aug 30 '21 at 18:00

1 Answers1

-2

First you need to install using brew

brew install portaudio
Sandeep Kothari
  • 405
  • 3
  • 6