when installing pyaudio, pip cannot find portaudio.h in /usr/local/include
Question:
I’m using mac osx 10.10
As the PyAudio Homepage said, I install the PyAudio using
brew install portaudio
pip install pyaudio
the installation of portaudio seems successful, I can find headers and libs in /usr/local/include and /usr/local/lib
but when I try to install pyaudio, it gives me an error that
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
^
1 error generated.
error: command 'cc' failed with exit status 1
actually it is in /usr/local/include
why can’t it find the file?
some answers to similar questions are not working for me(like using virtualenv, or compile it manually), and I want to find a simple way to solve this.
Answers:
Since pyAudio
has portAudio
as a dependency, you first have to install portaudio.
brew install portaudio
Then try: pip install pyAudio
. If the problem persists after installing portAudio
, you can specify the directory path where the compiler will be able to find the source programs (e.g: portaudio.h
). Since the headers should be in the /usr/local/include
directory:
pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio
For me on 10.10.5 the paths were under /opt/local
. I had to add /opt/local/bin
to my /etc/paths
file. And the command line that worked was
sudo pip install --global-option='build_ext' --global-option='-I/opt/local/include' --global-option='-L/opt/local/lib' pyaudio
You have to install portaudio first then link that file. Only then you can find that header file (i.e, portaudio.h). To install portaudio in mac by using HomeBrew
program use following commands.
brew install portaudio
brew link portaudio
pip install pyaudio
sudo is not needed if you’re admin. We should refrain using sudo as it messes up lots of permissions.
on Centos:
yum install -y portaudio portaudio-devel && pip install pyaudio
Just for the record for folks using MacPorts and not Homebrew:
$ [sudo] port install portaudio
$ pip install pyaudio --global-option="build_ext" --global-option="-I/opt/local/include" --global-option="-L/opt/local/lib"
First, you can use Homebrew to install portaudio.
brew install portaudio
Then try to find the portaudio path:
sudo find / -name "portaudio.h"
In my case it is at /usr/local/Cellar/portaudio/19.6.0/include
.
Run the command below to install pyaudio
pip install --global-option='build_ext' --global-option='-I/usr/local/Cellar/portaudio/19.6.0/include' --global-option='-L/usr/local/Cellar/portaudio/19.6.0/lib' pyaudio
On Raspbian:
sudo apt-get install python-pyaudio
On Ubuntu builds:
sudo apt-get install python-pyaudio
For Python3:
sudo apt-get install python3-pyaudio
If you are using anaconda/miniconda to manage your python environments then
conda install pyaudio
installs portaudio
at the same time as pyaudio
The following NEW packages will be INSTALLED:
portaudio pkgs/main/osx-64::portaudio-19.6.0-h647c56a_4
pyaudio pkgs/main/osx-64::pyaudio-0.2.11-py37h1de35cc_2
I needed to do the following to install PortAudio on Debian
sudo apt install portaudio19-dev
I also apt install
‘d python3-portaudio
before that, although it didn’t work. I’m not sure if that contributed as well.
On Termux (this is what worked for me):
pkg install python
bash -c "$(curl -fsSL https://its-pointless.github.io/setup-pointless-repo.sh)"
pkg install portaudio
pip install pyaudio
Source: pyaudio installing #6235
Adding a bit of robustness (in case of a non-default homebrew dir) to the snippet from @fukudama,
brew install portaudio
pip install --global-option='build_ext' --global-option="-I$(brew --prefix)/include" --global-option="-L$(brew --prefix)/lib" pyaudio
this is the tested answer for MacBook Pro m2 chip:
first find the location of the portaudio.h
file by
sudo find / -name "portaudio.h"
then, once you find the location, copy it and use it in this command.
LDFLAGS="-L/{opt/homebrew/Cellar/portaudio/19.7.0/}lib" CFLAGS="-I/{opt/homebrew/Cellar/portaudio/19.7.0}/include" pip3 install pyaudio
Here replace the location from { } into you file location hopefully this works. I have tried above solutions and this one worked for me.
I’m using mac osx 10.10
As the PyAudio Homepage said, I install the PyAudio using
brew install portaudio
pip install pyaudio
the installation of portaudio seems successful, I can find headers and libs in /usr/local/include and /usr/local/lib
but when I try to install pyaudio, it gives me an error that
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
^
1 error generated.
error: command 'cc' failed with exit status 1
actually it is in /usr/local/include
why can’t it find the file?
some answers to similar questions are not working for me(like using virtualenv, or compile it manually), and I want to find a simple way to solve this.
Since pyAudio
has portAudio
as a dependency, you first have to install portaudio.
brew install portaudio
Then try: pip install pyAudio
. If the problem persists after installing portAudio
, you can specify the directory path where the compiler will be able to find the source programs (e.g: portaudio.h
). Since the headers should be in the /usr/local/include
directory:
pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio
For me on 10.10.5 the paths were under /opt/local
. I had to add /opt/local/bin
to my /etc/paths
file. And the command line that worked was
sudo pip install --global-option='build_ext' --global-option='-I/opt/local/include' --global-option='-L/opt/local/lib' pyaudio
You have to install portaudio first then link that file. Only then you can find that header file (i.e, portaudio.h). To install portaudio in mac by using HomeBrew
program use following commands.
brew install portaudio
brew link portaudio
pip install pyaudio
sudo is not needed if you’re admin. We should refrain using sudo as it messes up lots of permissions.
on Centos:
yum install -y portaudio portaudio-devel && pip install pyaudio
Just for the record for folks using MacPorts and not Homebrew:
$ [sudo] port install portaudio
$ pip install pyaudio --global-option="build_ext" --global-option="-I/opt/local/include" --global-option="-L/opt/local/lib"
First, you can use Homebrew to install portaudio.
brew install portaudio
Then try to find the portaudio path:
sudo find / -name "portaudio.h"
In my case it is at /usr/local/Cellar/portaudio/19.6.0/include
.
Run the command below to install pyaudio
pip install --global-option='build_ext' --global-option='-I/usr/local/Cellar/portaudio/19.6.0/include' --global-option='-L/usr/local/Cellar/portaudio/19.6.0/lib' pyaudio
On Raspbian:
sudo apt-get install python-pyaudio
On Ubuntu builds:
sudo apt-get install python-pyaudio
For Python3:
sudo apt-get install python3-pyaudio
If you are using anaconda/miniconda to manage your python environments then
conda install pyaudio
installs portaudio
at the same time as pyaudio
The following NEW packages will be INSTALLED:
portaudio pkgs/main/osx-64::portaudio-19.6.0-h647c56a_4
pyaudio pkgs/main/osx-64::pyaudio-0.2.11-py37h1de35cc_2
I needed to do the following to install PortAudio on Debian
sudo apt install portaudio19-dev
I also apt install
‘d python3-portaudio
before that, although it didn’t work. I’m not sure if that contributed as well.
On Termux (this is what worked for me):
pkg install python
bash -c "$(curl -fsSL https://its-pointless.github.io/setup-pointless-repo.sh)"
pkg install portaudio
pip install pyaudio
Source: pyaudio installing #6235
Adding a bit of robustness (in case of a non-default homebrew dir) to the snippet from @fukudama,
brew install portaudio
pip install --global-option='build_ext' --global-option="-I$(brew --prefix)/include" --global-option="-L$(brew --prefix)/lib" pyaudio
this is the tested answer for MacBook Pro m2 chip:
first find the location of the portaudio.h
file by
sudo find / -name "portaudio.h"
then, once you find the location, copy it and use it in this command.
LDFLAGS="-L/{opt/homebrew/Cellar/portaudio/19.7.0/}lib" CFLAGS="-I/{opt/homebrew/Cellar/portaudio/19.7.0}/include" pip3 install pyaudio
Here replace the location from { } into you file location hopefully this works. I have tried above solutions and this one worked for me.