如何解决Ubuntu 18.04中PyAudio的安装错误(严重错误(找不到”portaudio.h”文件))

本文概述

  • 错误
通常, 你将能够使用以下命令通过PIP安装PyAudio:
pip install PyAudio

【如何解决Ubuntu 18.04中PyAudio的安装错误(严重错误(找不到” portaudio.h” 文件))】遗憾的是, 在某些Ubuntu发行版中, 构建pyaudio轮子时会遇到失败的例外情况。根据Python包装索引的描述, 转盘*旨在以与磁盘格式非常接近的方式包含与PEP 376兼容安装的所有文件。
错误当你尝试安装软件包时, 错误输出将是:
pip install pyaudioFailed building wheel for pyaudioRunning setup.py clean for pyaudioFailed to build pyaudioInstalling collected packages: pyaudioRunning setup.py install for pyaudio ... errorComplete output from command /Users/kj/Desktop/ml/gui/bin/python3 -u -c "import setuptools, tokenize; __file__='/private/var/folders/vd/8zl261fj35j8pst5659glmjc0000gn/T/pip-build-gj9ny3f9/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 /var/folders/vd/8zl261fj35j8pst5659glmjc0000gn/T/pip-45sl0b3v-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/kj/Desktop/ml/gui/include/site/python3.6/pyaudio:running installrunning buildrunning build_pycreating buildcreating build/lib.macosx-10.12-x86_64-3.6copying src/pyaudio.py -> build/lib.macosx-10.12-x86_64-3.6running build_extbuilding '_portaudio' extensioncreating build/temp.macosx-10.12-x86_64-3.6creating build/temp.macosx-10.12-x86_64-3.6/srcclang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DMACOSX=1 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/Users/kj/Desktop/ml/gui/include -I/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c src/_portaudiomodule.c -o build/temp.macosx-10.12-x86_64-3.6/src/_portaudiomodule.osrc/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found#include "portaudio.h"^~~~~~~~~~~~~1 error generated.error: command 'clang' failed with exit status 1

该错误基本上是由系统中缺少portaudio.h文件引起的。 PortAudio是一个免费的, 跨平台的开源音频I / O库。
解你可以使用以下命令在Ubuntu中安装dev portaudio软件包和pyaudio来解决此异常:
sudo apt-get install portaudio19-dev python-pyaudio

最后, 使用以下命令再次安装该软件包:
pip install PyAudio

而且你应该能够正确安装它而不会出现问题!
编码愉快!

    推荐阅读