29 June 2021

Fixing pyaudio installation errors in Ubuntu and Raspberry Pi

I don't understand why developers can't just write a script to automatically detect the OS and install dependencies automatically. When installing pyaudio, there's this error that shows up on Ubuntu:

ERROR: Command errored out with exit status 1:

...blah blah...

src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
    compilation terminated.
    error: command '/usr/bin/gcc' failed with exit code 1

The solution is to install the dependencies. Not all of the below dependencies are required, but it's safe to just copy-paste these one by one to get them installed...just to be sure.

sudo apt-get install -y libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
sudo apt-get install -y ffmpeg libav-tools

And finally...

sudo apt-get install -y python-pyaudio python3-pyaudio

or
sudo pip install pyaudio 

or 

sudo apt-get install -y python3-pyaudio 

or 

sudo apt-get install -y python-pyaudio

or
sudo -s
pip install pyaudio

Sources: source1, source2.

If the problem happens in Raspberry Pi, these are the steps:
Remove the directory PyAudio which is already present in /home/pi and then try these steps:
sudo apt-get install git
sudo git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
sudo apt-get install -y libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo apt-get install -y python-dev
cd pyaudio
sudo python setup.py install

Thats it! Have fun.

No comments: