Skip to content

Instantly share code, notes, and snippets.

@jiaaro
Last active May 2, 2024 10:15
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save jiaaro/9767512210a1d80a8a0d to your computer and use it in GitHub Desktop.
Save jiaaro/9767512210a1d80a8a0d to your computer and use it in GitHub Desktop.
How to install PyAudio into a VirtualEnv on Mac OS X 10.10

Install portaudio using homebrew (or method of your choice)

brew install portaudio

create $HOME/.pydistutils.cfg using the include and lib directories of your portaudio install:

[build_ext]
include_dirs=/Users/jrobert1271/homebrew/Cellar/portaudio/19.20140130/include/
library_dirs=/Users/jrobert1271/homebrew/Cellar/portaudio/19.20140130/lib/

Then in your virtualenv:

pip install --allow-external pyaudio --allow-unverified pyaudio pyaudio
@ewjoachim
Copy link

Thanks !

@rasmi
Copy link

rasmi commented Jul 17, 2015

Thanks!

@karadza3a
Copy link

Make sure you double-check the path in .cfg, mine was "/usr/local/Cellar/portaudio/19.20140130".

@algera
Copy link

algera commented Jul 7, 2016

💯

@exsurgo
Copy link

exsurgo commented Sep 19, 2016

Awesome!! Thanks!

@okofish
Copy link

okofish commented Nov 16, 2016

👌

@theSetOfR
Copy link

perfect!

@abhi18av
Copy link

abhi18av commented Jan 16, 2017

Hey, on my anaconda-pythn3.5 installation it raised the following warning

DEPRECATION: --allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.
DEPRECATION: --allow-unverified has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect.

Regarding my pip version

❯ pip3 --version
pip 9.0.1 from /Users/eklavya/anaconda/lib/python3.5/site-packages (python 3.5)

@cbcafiero
Copy link

If using Macports, tweak the recipe

port install portaudio

create $HOME/.pydistutils.cfg using the include and lib directories of your portaudio install:

[build_ext]
include_dirs=/opt/local/include/
library_dirs=/opt/local/lib/

Then in your virtualenv:

pip install --allow-external pyaudio --allow-unverified pyaudio pyaudio

@jnfran92
Copy link

Great, Thanks !

@ccarstens
Copy link

macOS 10.14.6

This solved it for me:
pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio

@chrislos
Copy link

@ccarstens Thanks! worked for me!

@RogerChu8
Copy link

macOS 10.14.6

This solved it for me:
pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio

I tried but got the following error:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
error: command 'gcc' failed with exit status 1

Is this something to do with Xcode installation?

Thanks.
-------- full list of error message below --------

/Users/roger/ml/env/lib/python3.7/site-packages/pip/_internal/commands/install.py:244: UserWarning: Disabling all use of wheels due to the use of --build-option / --global-option / --install-option.
cmdoptions.check_install_build_global(options)
Collecting pyaudio
Using cached PyAudio-0.2.11.tar.gz (37 kB)
Skipping wheel build for pyaudio, due to binaries being disabled for it.
Installing collected packages: pyaudio
Running setup.py install for pyaudio ... error
ERROR: Command errored out with exit status 1:
command: /Users/roger/ml/env/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nj/3sdbvf895vd9s0dtdlyw302r0000gn/T/pip-install-enh0aujj/pyaudio/setup.py'"'"'; file='"'"'/private/var/folders/nj/3sdbvf895vd9s0dtdlyw302r0000gn/T/pip-install-enh0aujj/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);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/nj/3sdbvf895vd9s0dtdlyw302r0000gn/T/pip-record-wslhmklz/install-record.txt --single-version-externally-managed --compile --install-headers /Users/roger/ml/env/bin/../include/site/python3.7/pyaudio
cwd: /private/var/folders/nj/3sdbvf895vd9s0dtdlyw302r0000gn/T/pip-install-enh0aujj/pyaudio/
Complete output (8 lines):
running build_ext
building '_portaudio' extension
creating build
creating build/temp.macosx-10.9-x86_64-3.7
creating build/temp.macosx-10.9-x86_64-3.7/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.7/include/python3.7m -c src/_portaudiomodule.c -o build/temp.macosx-10.9-x86_64-3.7/src/_portaudiomodule.o
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /Users/roger/ml/env/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nj/3sdbvf895vd9s0dtdlyw302r0000gn/T/pip-install-enh0aujj/pyaudio/setup.py'"'"'; file='"'"'/private/var/folders/nj/3sdbvf895vd9s0dtdlyw302r0000gn/T/pip-install-enh0aujj/pyaudio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);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/nj/3sdbvf895vd9s0dtdlyw302r0000gn/T/pip-record-wslhmklz/install-record.txt --single-version-externally-managed --compile --install-headers /Users/roger/ml/env/bin/../include/site/python3.7/pyaudio Check the logs for full command output.

@mcorderoaraya
Copy link

python3 -m easy_install pyobjc

@Mattia541993
Copy link

macOS 10.14.6

This solved it for me:
pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio

This worked for me Mac 10.15.5. Thank you!

@esantonja
Copy link

@ccarstens Thanks! worked for me!

@jpaxer
Copy link

jpaxer commented Jan 18, 2023

pip install --allow-external pyaudio --allow-unverified pyaudio pyaudio doesn't work for me. It says:

Usage:   
  pip install [options] <requirement specifier> [package-index-options] ...
  pip install [options] -r <requirements file> [package-index-options] ...
  pip install [options] [-e] <vcs project url> ...
  pip install [options] [-e] <local project path> ...
  pip install [options] <archive url/path> ...

no such option: --allow-unverified
```   FYI, I followed the steps in the original post.

 I am using MacOS Ventura 13.0 and need pyaudio for speechRecognition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment