How to install pyaudio on mac using Python 3?
Question:
I first tried:
pip install pyaudio
but I was told that
-bash: pip: command not found
Then I tried:
pip3 install pyaudio
Then I got:
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('rn', '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
but I had installed portaudio
brew install portaudio
Warning: portaudio-19.20140130 already installed
So what can I do?
Answers:
I’m assuming you are on a Mac. This is a simple issue to fix.
First install Xcode. Then restart your computer. Afterwards run the commands in sequence,
xcode-select --install
brew remove portaudio
brew install portaudio
pip3 install pyaudio
So to clarify, Xcode is installed through the App Store. Xcode command line tools are required for some installations, for others they are not. I’m including it here just to be on the safe side. You also probably do not need to uninstall and reinstall the formula via Homebrew, I did that to ensure that there would be absolutely no problems.
Edit: I have been told Homebrew requires Xcode. So just run the
xcode-select --install
command to be able to use Clang. Also what version of Mac are you on?
Steps:
I assume you are using a mac osx
-
download homebrew by pasting this code at any terminal point
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
-
After installing homebrew, install portaudio:
brew install portaudio
-
Finally install pyaudio using pip
pip install pyaudio
Note: Ensure you install homebrew if its not already installed
For a mac, I think you have to type this into Terminal:
sudo pip install pyaudio
Also, you might have to install Xcode like said in one of the answers.
Steps: I assume you are using a mac osx
download homebrew
by pasting this code at any terminal point /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After installing homebrew
, install portaudio
: brew install portaudio
Finally install pyaudio
using pip pip install pyaudio
Open the Terminal(located in the utilities folder in Applications) and follow the instructions:
With homebrew:
brew install portaudio
pip install pyaudio
Without homebrew:
cd Downloads
curl http://files.portaudio.com/archives/pa_stable_candidate_v190700_rc2_20210331.tgz
tar -xzf pa_stable_candidate_v190700_rc2_20210331.tgz
cd portaudio
pip3 install pyaudio --global-option="build_ext" --global-option="-I$(pwd)/include" --global-option="-L$(pwd)/lib"
In case of MacOS
brew install portaudio
pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio
Working with Homebrew failed for me on a Macbook Pro M1.
Instead, I installed portaudio from source http://files.portaudio.com/docs/v19-doxydocs/tutorial_start.html
and used
./configure && make
sudo make install
sudo cp include/pa_mac_os.h /usr/local/include
Obviously, there is a bug in the portaudio package for Mac M1, so I had to add the hack of the copy of the include file.
But then
python3 -m pip install pyaudio
and it worked.
(Im on a M1 MacBook Air) This was the first one working for me
brew install flac
pip uninstall pyaudio
brew uninstall portaudio
brew update
brew install portaudio
python3 -m pip install pyaudio --global-option="build_ext" --global-option="-I/opt/homebrew/include" --global-option="-L/opt/homebrew/lib"
pip install pyaudio
None of that worked for me, try instead:
CFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" python3 -m pip install pyaudio
If you want to install pyaudio in jupyter notebook then follow the below steps. Open the terminal and write the following command:
brew install portaudio
pip install pyaudio
Once the above step is done go to jupyter notebook and execute the below code.
pip install pyaudio
I ran into similar issue on macOs Ventura 13.2
.
Listing error and solution below in case someone else runs into it.
Error:
$ 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
Solution
I just had to do following,
brew install portaudio
pip3 install pyaudio
I first tried:
pip install pyaudio
but I was told that
-bash: pip: command not found
Then I tried:
pip3 install pyaudio
Then I got:
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('rn', '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
but I had installed portaudio
brew install portaudio
Warning: portaudio-19.20140130 already installed
So what can I do?
I’m assuming you are on a Mac. This is a simple issue to fix.
First install Xcode. Then restart your computer. Afterwards run the commands in sequence,
xcode-select --install
brew remove portaudio
brew install portaudio
pip3 install pyaudio
So to clarify, Xcode is installed through the App Store. Xcode command line tools are required for some installations, for others they are not. I’m including it here just to be on the safe side. You also probably do not need to uninstall and reinstall the formula via Homebrew, I did that to ensure that there would be absolutely no problems.
Edit: I have been told Homebrew requires Xcode. So just run the
xcode-select --install
command to be able to use Clang. Also what version of Mac are you on?
Steps:
I assume you are using a mac osx
-
download homebrew by pasting this code at any terminal point
/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)” -
After installing homebrew, install portaudio:
brew install portaudio -
Finally install pyaudio using pip
pip install pyaudio
Note: Ensure you install homebrew if its not already installed
For a mac, I think you have to type this into Terminal:
sudo pip install pyaudio
Also, you might have to install Xcode like said in one of the answers.
Steps: I assume you are using a mac osx
download homebrew
by pasting this code at any terminal point /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After installing homebrew
, install portaudio
: brew install portaudio
Finally install pyaudio
using pip pip install pyaudio
Open the Terminal(located in the utilities folder in Applications) and follow the instructions:
With homebrew:
brew install portaudio
pip install pyaudio
Without homebrew:
cd Downloads
curl http://files.portaudio.com/archives/pa_stable_candidate_v190700_rc2_20210331.tgz
tar -xzf pa_stable_candidate_v190700_rc2_20210331.tgz
cd portaudio
pip3 install pyaudio --global-option="build_ext" --global-option="-I$(pwd)/include" --global-option="-L$(pwd)/lib"
In case of MacOS
brew install portaudio
pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio
Working with Homebrew failed for me on a Macbook Pro M1.
Instead, I installed portaudio from source http://files.portaudio.com/docs/v19-doxydocs/tutorial_start.html
and used
./configure && make
sudo make install
sudo cp include/pa_mac_os.h /usr/local/include
Obviously, there is a bug in the portaudio package for Mac M1, so I had to add the hack of the copy of the include file.
But then
python3 -m pip install pyaudio
and it worked.
(Im on a M1 MacBook Air) This was the first one working for me
brew install flac
pip uninstall pyaudio
brew uninstall portaudio
brew update
brew install portaudio
python3 -m pip install pyaudio --global-option="build_ext" --global-option="-I/opt/homebrew/include" --global-option="-L/opt/homebrew/lib"
pip install pyaudio
None of that worked for me, try instead:
CFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" python3 -m pip install pyaudio
If you want to install pyaudio in jupyter notebook then follow the below steps. Open the terminal and write the following command:
brew install portaudio
pip install pyaudio
Once the above step is done go to jupyter notebook and execute the below code.
pip install pyaudio
I ran into similar issue on macOs Ventura 13.2
.
Listing error and solution below in case someone else runs into it.
Error:
$ 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
Solution
I just had to do following,
brew install portaudio
pip3 install pyaudio