portaudio.h: 没有那个文件或目录

portaudio.h: No such file or directory

我在 ubuntu 16.04 中尝试使用 pip3 安装 pyaudio 时遇到以下错误:

Collecting pyaudio
  Downloading PyAudio-0.2.11.tar.gz
Installing collected packages: pyaudio
  Running setup.py install for pyaudio ... error
    Complete output from command /usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-mxgvewdb/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-v55chjee-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    copying src/pyaudio.py -> build/lib.linux-x86_64-3.5
    running build_ext
    building '_portaudio' extension
    creating build/temp.linux-x86_64-3.5
    creating build/temp.linux-x86_64-3.5/src
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.5/src/_portaudiomodule.o
    src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
    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-mxgvewdb/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-v55chjee-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-mxgvewdb/pyaudio/

这应该有帮助

$ sudo apt-get install portaudio19-dev python-pyaudio python3-pyaudio

测试于 Ubuntu 18.04Python 3.7.2pyaudio 0.2.11

2021 年 1 月 8 日添加:

在 Ubuntu 20.04 你必须使用:

$ sudo apt install portaudio19-dev python3-pyaudio

对于Centos7/RHEL:

yum install portaudio-devel alsa-lib-devel portaudio
pip install pyaudio --user

对于 MacOS:

brew install portaudio
pip3 install pyaudio

对于 Windows,
这是我一直在经历的...

有几种安装 PortAudio 的方法

啊!
pyaudio的soucefile中的"min()"宏_portaudiomodule.c麻烦,手动注释掉

  • pip install pyaudio --no-clean
  • 在临时目录中找到 _portaudiomodule.c 并手动注释掉“min()”宏
    例如c:\Temp\pip-install-yysb8bme\pyaudio_c92585\src\_portaudiomodule.c
  • pip install 来自那个目录
    例如pip install c:\Temp\pip-install-yysb8bme\pyaudio_c92585\

或者,第三方轮子

  • 说:

pip install pipwin
pipwin install pyaudio