34

Trying to install pyaudio with instructions per here:

$ git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
$ cd pyaudio
$ sudo python setup.py install
running install
running build
running build_py
running build_ext
building '_portaudio' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
In file included from /usr/include/python2.7/Python.h:8:0,
                 from src/_portaudiomodule.c:28:
/usr/include/python2.7/pyconfig.h:1161:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]
/usr/include/features.h:215:0: note: this is the location of the previous definition
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

What's going wrong in my installation?

Mittenchops
  • 18,633
  • 33
  • 128
  • 246
  • 8
    gcc can't find the PortAudio header files, did you install the PortAudio dev package (e.g. `apt-get install libportaudio-dev` for ubuntu)? As a side note, at least in ubuntu pyaudio is already in the repository for both python 2 and 3, and can be installed via `apt-get install python(3)-pyaudio`. – l4mpi Nov 16 '13 at 20:10
  • 1
    Possible cross-post: http://stackoverflow.com/questions/5921947/pyaudio-installation-error-command-gcc-failed-with-exit-status-1?rq=1 – Paul Dec 09 '15 at 17:11
  • what worked for me is Cerin's comment in AI_ROBOT's answer. Using Ubuntu 20.04.3 LTS – YoussefDir Oct 12 '21 at 05:43

16 Answers16

63

Sorry about the inappropriate answer last time, I will post the solution of the question. It might be helpful for Ubuntu distributions.

  1. First we need to install portaudio modules: sudo apt-get install libasound-dev

  2. Download the portaudio archive from: http://files.portaudio.com/download.html

  3. Unzip the archive: tar -zxvf [portaudio.tgz]

  4. Enter the directory, then run: ./configure && make

  5. Install: sudo make install

  6. And finally: sudo pip install pyaudio

  7. Check the version of pyaudio, it should be 0.2.9

AI_ROBOT
  • 958
  • 1
  • 9
  • 19
  • 38
    You don't need to download tarballs. You can just do `sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0` – Cerin Dec 08 '16 at 02:44
  • 1
    @Cerin, That actually didn't work for me, so I had to follow the tarball instructions, so it's working. – alex Jul 09 '17 at 21:37
  • @alex What OS are you on? It worked fine for me on Ubuntu 16.04. – Cerin Jul 10 '17 at 03:13
  • @Cerin, 16.04 as well, for some reason the apt-get method couldn't locate the package. There was also a seg-fault somewhere in there as well, I think when I did apt-get update. That's probably a different issue that I'm going to have to figure out eventually. But I did manage to get the portaudio working from the tar file. – alex Jul 10 '17 at 21:18
  • Thanks. As yum has restricted only for local repo, for centos this solution worked me. – Shahid Hussain Sep 23 '19 at 11:09
  • @Cerin Works fine on Ubuntu 18.04 as well – Nukul Khadse Apr 09 '20 at 02:55
  • In case you can't install libasound-dev just follow look at that link: https://bugs.launchpad.net/ubuntu/+source/alsa-lib/+bug/264534 – Tarlan Ahad Jun 12 '22 at 12:27
24

This worked for me:

sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
sudo apt-get install ffmpeg libav-tools
sudo pip install pyaudio
mjk
  • 2,443
  • 4
  • 33
  • 33
sayantan ghosh
  • 426
  • 1
  • 6
  • 8
21

On Ubuntu:

sudo apt-get install python-pyaudio

or

sudo apt-get install python3-pyaudio
Aaron
  • 675
  • 6
  • 12
13

Install 2 things,

sudo apt-get install portaudio19-dev python-pyaudio

and then,

pip install pyaudio
Mohideen bin Mohammed
  • 18,813
  • 10
  • 112
  • 118
7

For Centos7:

sudo yum install -y portaudio-devel
sudo pip install pyaudio
Vitaliy
  • 416
  • 6
  • 9
6

For Windows :

Install using pip:

 python -m pip install pyaudio

if pip is not already bundled with your installation of Python, get it here.

For Mac OS X :

Use Homebrew to install the prerequisite portaudio library, then install PyAudio using pip:

 brew install portaudio
 pip install pyaudio

pip will download the PyAudio source and build it for your version of Python.

For Debian/Ubuntu :

Use the package manager to install PyAudio:

 sudo apt-get install python-pyaudio python3-pyaudio

If the latest version of PyAudio is not available, install it using pip:

pip install pyaudio

For better isolation from system packages, consider installing PyAudio in a virtual environment

PyAudio Source :

Source is available for download at the Python Package Index (PyPI): here!

Or clone the git repository:

git clone https://people.csail.mit.edu/hubert/git/pyaudio.git

credits: PyAudio and GitHub:Speech_Recognition

Imran S M
  • 466
  • 2
  • 9
  • 20
3
  • First we need to install portaudio modules: sudo apt-get install libasound-dev

  • Download the portaudio archive from: http://portaudio.com/download.html

  • Unzip the archive: tar -zxvf [portaudio.tgz]

  • Enter the directory, then run: ./configure && make

  • Install: sudo make install

  • And Then: sudo pip install pyaudio

  • Update & Upgrade the system to fix all broken libraries

  • sudo apt update && sudo apt upgrade

Sindhukumari P
  • 324
  • 2
  • 6
2
sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
sudo apt-get install ffmpeg# libav-tools
sudo pip install pyaudio

as sayantan ghosh told (in my case, it's error with libav-tools) and

sudo apt-get install python3-pyaudio

as Aaron told, then pip install pyaudio

these steps works for me, Im in ubuntu 20.04

lam vu Nguyen
  • 433
  • 4
  • 9
1

this is work for me

sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0

After that run this command

pip install pyaudio --user
DB ms
  • 11
  • 1
0

I am using kali linux 2.0, do as follows:

apt-get install portaudio19-dev python-pyaudio

then:

pip install pyaudio

this worked for me.

c0d3x27
  • 193
  • 2
  • 15
0

Download PyAudio from the link below: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio Then, install this file using the command:

pip install (complete filepath)

Example:

pip install C:\Users\(Username)\Downloads\PyAudio-0.2.11-cp39-cp39-win_amd64.whl
Anurag A S
  • 725
  • 10
  • 23
0

On Manjaro(Arch Linux) sudo pacman -S python-pyaudio

0

I came across this question while getting pyaudio working in an alpine linux container (python:3.9-alpine).

There were some additional packages to install in this case. I'll post what I had to do in case it's useful for someone.

apk add --no-cache py3-pyaudio portaudio-dev gcc musl-dev
pip install pyaudio

The pyaudio pip install needs gcc and also the dev files included in musl-dev package.

BenCaldwell
  • 323
  • 1
  • 15
0

I could resolved PyAudio error after a long search

Hope this can help someone.

First you find the python version using : python --version (check both Pycharm and JupyterLab as I had 3.7.6 and 3.10.4 different version and move to correct directory - I pasted the same version whl file in same directory "may be there is another way of doing it - suggestions welcome" )

Once this file is placed in the same directory - "PyAudio-0.2.11-cp37-cp37m-win_amd64.whl" you can use pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl directly

Other findings :

In case the version and file not matching you will get this error

ERROR: PyAudio-0.2.11-cp310-cp310-win32.whl is not a supported wheel on this platform.

simple "pip install pyaudio" will not work (As read on internet its not working beyond 3.6)

Ferdinando
  • 964
  • 1
  • 12
  • 23
-1

Disclaimer - For Linux terminal command

  1. Run pip install wheel
  2. Download this https://github.com/Uberi/speech_recognition Inside above-mentioned folder
  3. Run pip install ./third-party/WHEEL_FILENAME Here Choose your WHEEL from https://github.com/Uberi/speech_recognition/tree/master/third-party

mine was (Linux) - PyAudio-0.2.11.tar.gz

Then Finally Run: pip install ./third-party/PyAudio-0.2.11.tar.gz (replace pip with pip3 if using Python 3)

kkgarg
  • 1,246
  • 1
  • 12
  • 28
-3

try this command pip install PyAudio

Ab uph
  • 1
  • Welcome to SO! This solution was already mentioned in several answers ([for example](https://stackoverflow.com/a/57947026/6682517)). – Sergey Shubin Jun 30 '20 at 12:24