TroubleChute Logo
PYTHON

Fix/Install PyAudio


Published: Jan 5, 2023
Last Edit: Jan 6, 2023
Raspberry Pi Python
248 Words, 1 Minute.

What went wrong?

Well, the normal installation command of:

1
pip3 install pyaudio

Encountered an error that ended with:

1
2
3
4
5
6
7
8
9 | #include "portaudio.h"
        |          ^~~~~~~~~~~~~
  compilation terminated.
  error: command '/usr/bin/aarch64-linux-gnu-gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pyaudio
Failed to build pyaudio
ERROR: Could not build wheels for pyaudio which use PEP 517 and cannot be installed directly

Yours may differ, of course.

There are a few fixes and you should be able to install this. Heck, I’m trying to install this on a Raspberry Pi 4.

Fixing the install

Make sure pip, setuptools, and wheel are up to date:

1
pip3 install --upgrade pip setuptools wheel

Then, we’ll install the required binaries/libraries for building PyAudio:

1
sudo apt install build-essential portaudio19-dev

Check Python version

I’m using Python v 3.11, but as far as I understand at the time of writing the minimum requirement for this version is Python 3.9+.

Everything works!

Things should be happy at this point. Run pip3 install pyaudio again, and it should install.

If things don’t, some of the other fixes I’ve come across are:

To fix ERROR: Could not build wheels for xmlsec which use PEP 517 and cannot be installed directly:

1
sudo apt-get install libxml2-dev libxmlsec1-dev

And other fixes like:

1
sudo apt-get install -y pkg-config
1
sudo apt-get install -y pkg-config

Using an Apple M1 or M2?

Things are still new. See Macbook m1 and python libraries

TCNO TechNobo / TroubleChute © Wesley Pyburn (TechNobo / TroubleChute)