Ubuntu 18LTS下PyAudio安装失败求助
Hey, let's fix that PyAudio installation issue you're having on Ubuntu 18.04 LTS!
Looking at your error log, the critical line that tells us what's wrong is:
src/_portaudiomodule.c:29:10: fatal error: portaudio.h: No such file or directory
The problem here is that libportaudio2 (which you installed) is just the runtime library for PortAudio—it doesn't include the header files and development resources needed to compile PyAudio from source. You need the dedicated development package instead.
Here's how to fix it step by step:
Install the PortAudio development package
Run this command to getportaudio19-dev, which includes the missingportaudio.hand everything else required for compiling PyAudio:sudo apt-get update && sudo apt-get install portaudio19-devReinstall PyAudio properly
Now that the development files are in place, re-run the install command. And since you saw those cache permission warnings, using-Hwith sudo ensures the home directory context is set correctly to avoid those issues:sudo -H python -m pip install pyaudio
Quick extra tips:
- If you need PyAudio for Python 3 instead of Python 2, just swap out
pythonforpython3in the install command:sudo -H python3 -m pip install pyaudio - You already have
libasound-devinstalled, which is the ALSA audio system library PyAudio relies on—no need to modify that installation.
内容的提问来源于stack exchange,提问作者echo

