Last Updated on 2023-12-28 by Clay
Problem
Today I installed pyaudio on my new Linux laptop (a python package for sound recording), I encountered an error I never met:
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
╰─> [18 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-310
creating build/lib.linux-x86_64-cpython-310/pyaudio
copying src/pyaudio/__init__.py -> build/lib.linux-x86_64-cpython-310/pyaudio
running build_ext
building 'pyaudio._portaudio' extension
creating build/temp.linux-x86_64-cpython-310
creating build/temp.linux-x86_64-cpython-310/src
creating build/temp.linux-x86_64-cpython-310/src/pyaudio
gcc -pthread -B /home/clay/Tools/anaconda3/envs/llms/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/clay/Tools/anaconda3/envs/llm
s/include -fPIC -O2 -isystem /home/clay/Tools/anaconda3/envs/llms/include -fPIC -I/usr/local/include -I/usr/include -I/home/clay/Tools/anaconda3/envs/llms/include/python3.10 -c src/pyaudio/d
evice_api.c -o build/temp.linux-x86_64-cpython-310/src/pyaudio/device_api.o
src/pyaudio/device_api.c:9:10: fatal error: portaudio.h: No such file or directory
9 | #include "portaudio.h"
| ^~~~~~~~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
[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
Solution
We can focus at the compile error: 9 | #include “portaudio.h”, it means the current system may lack some related libraries.
After searching the discussions of stackoverflow, I installed the portaudio19-dev and it will install the PortAudio development files and the head file portaudio.h.
sudo apt install portaudio19-dev
And then, we can try to install pyaudio package again. I think it will be fine!
pip3 install pyaudio