portaudio.h: No such file or directory

Question:

I got the following error while trying to install pyaudio using pip3 in ubuntu 16.04:

Collecting pyaudio
  Downloading PyAudio-0.2.11.tar.gz
Installing collected packages: pyaudio
  Running setup.py install for pyaudio ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-mxgvewdb/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-v55chjee-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    copying src/pyaudio.py -> build/lib.linux-x86_64-3.5
    running build_ext
    building '_portaudio' extension
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/src
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.5/src/_portaudiomodule.o
    src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-mxgvewdb/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-v55chjee-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-mxgvewdb/pyaudio/
Asked By: Monojit Sarkar

||

Answers:

This should help

$ sudo apt-get install portaudio19-dev python-pyaudio python3-pyaudio

Tested on Ubuntu 18.04, Python 3.7.2, pyaudio 0.2.11

Added 8th of Jan 2021:

On Ubuntu 20.04 you have to use:

$ sudo apt install portaudio19-dev python3-pyaudio
Answered By: Most Wanted

For Centos7/RHEL:

yum install portaudio-devel alsa-lib-devel portaudio
pip install pyaudio --user
Answered By: alessiosavi

For MacOS (Intel/Apple Silicon):

Step 1:

brew install portaudio

Step 2:

brew --prefix portaudio  

The output provided from the above command, will be required in Step 3, which will look something similar to /opt/homebrew/opt/portaudio

Step 3:

Create .pydistutils.cfg in your home directory

sudo nano ~/.pydistutils.cfg

then paste the following in the file, save and exit

[build_ext]
include_dirs=<PATH FROM STEP 2>/include/
library_dirs=<PATH FROM STEP 2>/lib/

Step 4:

pip3 install pyaudio
Answered By: WMRamadan

For Windows,
here’s what I’ve been going through…

There’re several ways to install PortAudio

Arrh!
the "min()" macro in pyaudio’s soucefile _portaudiomodule.c is troublesome, comment it out manually

  • pip install pyaudio --no-clean
  • find _portaudiomodule.c in the temp directory and manually comment-out the "min()" macro
    e.g. c:Temppip-install-yysb8bmepyaudio_c92585src_portaudiomodule.c
  • pip install from that directory
    e.g. pip install c:Temppip-install-yysb8bmepyaudio_c92585

Or,3rd party wheels

pip install pipwin
pipwin install pyaudio

Answered By: caoanan

works on WSL (windows subsystem for Linux) as it installs Ubuntu

sudo apt install portaudio19-dev python3-pyaudio 

but you get the following:-
The following packages were automatically installed and are no longer required:
accountsservice-ubuntu-schemas libmessaging-menu0 libunity-gtk2-parser0 libunity-gtk3-parser0 ubuntu-touch-sounds
unity-gtk-module-common
Use ‘sudo apt autoremove’ to remove them.
The following additional packages will be installed:
libasound2-dev libjack-dev libjack0 libportaudio2 libportaudiocpp0 pkg-config uuid-dev
Suggested packages:
libasound2-doc jackd1 portaudio19-doc python-pyaudio-doc
The following packages will be REMOVED:
libjack-jackd2-0
The following NEW packages will be installed:
libasound2-dev libjack-dev libjack0 libportaudio2 libportaudiocpp0 pkg-config portaudio19-dev python3-pyaudio
uuid-dev
0 upgraded, 9 newly installed, 1 to remove and 0 not upgraded.
Need to get 704 kB of archives.
After this operation, 3606 kB of additional disk space will be used.

Then after saying ‘Y’ to installing it works.

Trouble is how do I then use it to play LPC files?

Answered By: Stephen Adams