Install pyaudio inside Toolbox fails

I created my first toolbox:
toolbox create groundstation and toolbox enter groundstation then installed pip via sudo dnf install pip3.

Then I ran this command to install some more stuff I need to run a python script:
pip3 install opencv-python Pillow matplotlib basemap pymavlink haversine pyaudio pyserial

But pyaudio fails to install:

Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for pyaudio (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-312
      creating build/lib.linux-x86_64-cpython-312/pyaudio
      copying src/pyaudio/__init__.py -> build/lib.linux-x86_64-cpython-312/pyaudio
      running build_ext
      building 'pyaudio._portaudio' extension
      creating build/temp.linux-x86_64-cpython-312
      creating build/temp.linux-x86_64-cpython-312/src
      creating build/temp.linux-x86_64-cpython-312/src/pyaudio
      gcc -fno-strict-overflow -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -fexceptions -fcf-protection -fexceptions -fcf-protection -fexceptions -fcf-protection -fPIC -I/usr/local/include -I/usr/include -I/usr/include/python3.12 -c src/pyaudio/device_api.c -o build/temp.linux-x86_64-cpython-312/src/pyaudio/device_api.o
      error: command 'gcc' failed: No such file or directory
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyaudio
Failed to build pyaudio
ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects

Googling shows people solved it by installing portaudio19-dev but I can’t install that:

sudo dnf install portaudio19-dev
Last metadata expiration check: 0:03:47 ago on Fri 02 Aug 2024 16:42:08 CEST.
No match for argument: portaudio19-dev
Error: Unable to find a match: portaudio19-dev

How to install pyaudio via pip in a Toolbox?

It’s looking for gcc and it’s not installed in your toolbox. You might want to install basic compilation and build tools in your toolbox first:

sudo dnf install gcc

If you want to install all the tools you’ll likely need in one go:

sudo dnf group install development-tools
2 Likes

Added audio, python, toolbx

Apparently, pip3 install pyaudio won’t work. Instead, following the official documentation of pyaudio, by default it should not be installed via pip3. This worked:

sudo dnf install python3-pyaudio

Thanks for your quick support btw, much appreciated! Got it all working now.

edit: I now learned the hard way, you should install any dependencies for your python apps via dnf, not pip, unless its not available via pip3. Otherwise it won’t run. Weird errors. Mostly to do with opencv.

I removed the container (podman ps to list it and podman remove …` to remove it) and created a new toolbox container, then installed the dependencies I needed via dnf:

sudo dnf install python3-pyaudio python3-tkinter python3-pillow python3-matplotlib python3-basemap python3-opencv

It will install a shitload more than via pip3, but at least my program runs now.

2 Likes