先放几个报错方便同志们能搜索到:
error: command ‘x86_64-linux-gnu-gcc’ failed with exit status 1
ERROR: Failed building wheel for pyaudio
src/_portaudiomodule.c:28:20: fatal error: Python.h: 没有那个文件或目录
ERROR: Command errored out with exit status 1: /usr/bin/python3.6 -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"’"’/tmp/pip-install-nmslq77e/pyaudio_3229705d540e4febb0b1130ddbd6a7dd/setup.py’"’"’; file=’"’"’/tmp/pip-install-nmslq77e/pyaudio_3229705d540e4febb0b1130ddbd6a7dd/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-record-jl5t8c7a/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.6/pyaudio Check the logs for full command output.
我的ubuntu配置:
ubuntu16.04
python3.6.12
python3.6适配的pip
解决办法:
不用pip下载,使用apt下载。原因我是没搞懂。
apt下载命令:
sudo apt-get install python-pyaudio python3-pyaudio
安装成功:
其他方法:
其他博主说是缺少portaudio库开发包(portaudio19-dev)以及python开发包(python-all-dev)。需要先安装。我自己使用未成功,依旧报错如上。
方法命令:
sudo apt-get install portaudio19-dev python-all-dev python3-all-dev
pip3 install pyaudio
====================================================
2021年1月6日新更:
按我之前博客中第一个方法后,的确是安装成功了,但是调用的时候又出现新的问题。
报错 提示:
Please build and install the PortAudio Python bindings first
表示缺少相关环境的搭建。
后面在pyaudio官网找到问题所在:
必须事先安装portaudio19-dev和python-dev
安装portaudio19-dev:
1、到官网下载pa_stable_v190600_20161030.tgz(点击下载)
2、下载之后解压进入文件夹
tar -zvxf pa_stable_v190600_20161030.tgz
cd portaudio
3、依次输入以下命令
./configure
make
make install
4、安装依赖库(退出文件夹)
sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
安装python-dev:
sudo apt-get install python3.6-dev
我的环境是使用python3.6的,所有命令中python后面跟上了3.6的版本号。其他环境的自行弄。
安装完这两个依赖之后再pip3 install pyaudio就没有什么问题了