41

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('\r\n', '\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('\r\n', '\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/
Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
Monojit Sarkar
  • 657
  • 1
  • 5
  • 15
  • You could try to install `libportaudio-dev`. – ikreb Feb 08 '18 at 17:13
  • Possible duplicate of [Pyaudio installation error - 'command 'gcc' failed with exit status 1'](https://stackoverflow.com/questions/5921947/pyaudio-installation-error-command-gcc-failed-with-exit-status-1) – Nikolay Shmyrev Feb 09 '18 at 08:17
  • Nikolay is not a duplicate, given how that question is 7 years old and any answer provided will probably reference an old version and wont work on current OS – Manuel G Jun 11 '18 at 08:21

5 Answers5

81

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
Smart Manoj
  • 5,230
  • 4
  • 34
  • 59
Most Wanted
  • 6,254
  • 5
  • 53
  • 70
5

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
WMRamadan
  • 974
  • 1
  • 11
  • 25
5

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:\Temp\pip-install-yysb8bme\pyaudio_c92585\src\_portaudiomodule.c
  • pip install from that directory
    e.g. pip install c:\Temp\pip-install-yysb8bme\pyaudio_c92585\

Or,3rd party wheels

pip install pipwin
pipwin install pyaudio

caoanan
  • 554
  • 5
  • 20
  • 1
    This worked for me on windows 10, thanks! – masterop Apr 08 '21 at 09:34
  • I could not find the min() macro in _portaudiomodule.c ? Could you give some more details here? – Simon Fakir Nov 03 '22 at 22:01
  • @SimonFakir There might be several conflicting copy of "min()". Therefore, I have to remove it manually in my last trail. If you can't find it, that's fine. Congratulations, no conflict! – caoanan Nov 08 '22 at 17:05
2

For Centos7/RHEL:

yum install portaudio-devel alsa-lib-devel portaudio
pip install pyaudio --user
alessiosavi
  • 2,753
  • 2
  • 19
  • 38
1

For Arch/Manjaro/EndeavourOS/Parabola/Frugalware2​/Chakra:

sudo pacman -Sy portaudio python-pyaudio
LoGo124
  • 11
  • 2
  • 2
    While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Yunnosch May 09 '23 at 11:00
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 09 '23 at 18:40
  • One doesn't have to install `python-pyaudio` globally. It can be installed per python environment. – Robert Brisita Jun 16 '23 at 13:50