如何修复 pyaudio 'fatal error: portaudio.h: No such file or directory'

问题:

你正在尝试使用 pip install -U pyaudio 或类似命令安装 pyaudio,但你看到类似这样的错误消息

pyaudio_compile_error.txt
    src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
     #include "portaudio.h"
                           ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-jgxnwixs/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-c3blzlv5-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-jgxnwixs/pyaudio/

解决方案

你需要安装 portaudio 库。在 Debian/Ubuntu 上你可以使用

install_portaudio.sh
sudo apt install portaudio19-dev

在其他系统上,要么在你的包管理器中搜索 portaudio,要么从 http://www.portaudio.com/ 下载库


Check out similar posts by category: Python