0

I am trying to install pyaudio on a Mac.

Here is what I have done:

  • Installed python 3.9.7
  • Installed homebrew
  • Removed portaudio (brew remove portaudio)
  • Installed portaudio (brew install portaudio)

Now I am trying to install pyaudio:

python3 -m pip install pyaudio (same result for pip3 install pyaudio)

This is the error message that I get:

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.9/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/hc/z83533l573lc7bbdnfqd7jzw0000gn/T/pip-install-ukm0_nma/pyaudio_11253f82c20448a3a6ab37fa24ca3049/setup.py'"'"'; __file__='"'"'/private/var/folders/hc/z83533l573lc7bbdnfqd7jzw0000gn/T/pip-install-ukm0_nma/pyaudio_11253f82c20448a3a6ab37fa24ca3049/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'"'"'))' install --record /private/var/folders/hc/z83533l573lc7bbdnfqd7jzw0000gn/T/pip-record-giib8e7d/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/hc/z83533l573lc7bbdnfqd7jzw0000gn/T/pip-install-ukm0_nma/pyaudio_11253f82c20448a3a6ab37fa24ca3049/
    Complete output (16 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.9
    copying src/pyaudio.py -> build/lib.macosx-10.9-x86_64-3.9
    running build_ext
    building '_portaudio' extension
    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/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
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/hc/z83533l573lc7bbdnfqd7jzw0000gn/T/pip-install-ukm0_nma/pyaudio_11253f82c20448a3a6ab37fa24ca3049/setup.py'"'"'; __file__='"'"'/private/var/folders/hc/z83533l573lc7bbdnfqd7jzw0000gn/T/pip-install-ukm0_nma/pyaudio_11253f82c20448a3a6ab37fa24ca3049/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'"'"'))' install --record /private/var/folders/hc/z83533l573lc7bbdnfqd7jzw0000gn/T/pip-record-giib8e7d/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.9/include/python3.9/pyaudio Check the logs for full command output.
WARNING: You are using pip version 21.2.3; however, version 21.2.4 is available.
You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 -m pip install --upgrade pip' command.

What can I do?

I have tried the various suggestions in the search engines and YouTube.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Martin
  • 1
  • 1
  • Does this answer your question? [when installing pyaudio, pip cannot find portaudio.h in /usr/local/include](https://stackoverflow.com/questions/33513522/when-installing-pyaudio-pip-cannot-find-portaudio-h-in-usr-local-include) – Gino Mempin Sep 14 '21 at 13:19
  • Thanks, but no it does not solve the problem. The file "portaudio.h" is not downloaded (cannot find searching "This Mac") and I **think** this is why the install terminates. I tried all the options given: Homebrew is installed (OK), Portaudio is installed (OK), xcode is installed (OK). Yet PyAudio fails. – Martin Sep 14 '21 at 16:26
  • Are you sure that `brew install portaudio` was successful? Doing `brew info portaudio` should tell you where it's installed (it should show a path like /usr/local/Cellar/portaudio/..), which should have the include/portaudio.h file. Then you can explicitly tell pip the path to the include folder. – Gino Mempin Sep 14 '21 at 21:29
  • (base) frederik@Frederiks-MacBook-Air ~ % ```brew info portaudio``` portaudio: stable 19.7.0 (bottled), /opt/homebrew/Cellar/portaudio/19.7.0 (33 files, 560KB) * Poured from bottle on 2021-09-15 at 09:52:43 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/portaudio.rb ==> Dependencies Build: pkg-config ✘ ==> Options --HEAD Install HEAD version ==> Analytics install: 8,062 (30 days), 24,508 (90 days), 99,287 (365 days) install-on-request: 3,515 (30 days), 10,571 (90 days), 44,494 (365 days) build-error: 0 (30 days) What do I need to do now? Thanks... – Martin Sep 16 '21 at 08:06
  • `/opt/homebrew/Cellar/portaudio/19.7.0/include` _should_ have portaudio.h. Then you can try [one of the answers from the link I shared](https://stackoverflow.com/a/33821084/2745495), where you _explicitly_ tell pip where to find portaudio.h (by giving the path to the `/include` directory). It seems your Homebrew installs stuff on a non-regular dir. Normally it's on `/usr/local/`. – Gino Mempin Sep 16 '21 at 08:36

1 Answers1

0

Download Pyaudio and install it manually

Download Link

Another guide

Homebrew and building PyAudio also requires installing the Command Line Tools for Xcode

Linux guide

You can use the Linux guide to install it on your mac

There are other ways too: Use Anaconda: Install anaconda and use its package manager and other abilities. Use Virtual Envs: Install Pyenv

  • 1
    Thanks, but the download link you included (https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio) is for Windows only. Does this exist for a Mac also? – Martin Sep 14 '21 at 16:36
  • I don't know if it exists for Mac, But you can try to install it on Mac, it is a Wheel file!!. – aniran mohammadpour Sep 16 '21 at 16:48