如何安装 PyAudio 0.2.11 Fedora

How to install PyAudio 0.2.11 Fedora

我想为 Python 使用 SpeechRecognition 库,但是当我尝试 运行 一个使用麦克风的程序时,我打算这样做,但出现错误

"PyAudio 0.2.11 or later is required (found version 0.2.9)"

所以我做了一些挖掘,找到了如何使用 apt-get 安装它。不幸的是我 运行 Fedora 26,所以我必须使用 yum 来安装我的包,当我寻找使用它安装 PyAudio 的方法时,我只能找到版本 0.2.9。

每当我尝试做

pip install pyaudio

我收到以下错误:

Failed building wheel for pyaudio Running setup.py clean for pyaudio Failed to build pyaudio Installing collected packages: pyaudio Running setup.py install for pyaudio ... error Complete output from command /usr/bin/python2 -u -c "import setuptools, tokenize;file='/tmp/pip-build-ZiuxD3/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-a2Iwxv-record/install-record.txt --single-version-externally-managed --compile: running install running build running build_py creating build creating build/lib.linux-x86_64-2.7 copying src/pyaudio.py -> build/lib.linux-x86_64-2.7 running build_ext building '_portaudio' extension creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/src gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory error: command 'gcc' failed with exit status 1

----------------------------------------

Command "/usr/bin/python2 -u -c "import setuptools, tokenize;file='/tmp/pip-build-ZiuxD3/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-a2Iwxv-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-ZiuxD3/pyaudio/

你需要:

sudo dnf install portaudio-devel redhat-rpm-config

接下来就可以安装pyaudio了

pip install --user pyaudio

注:

  1. yum 已弃用,请改用 dnf。
  2. 当你看到 compilation/building 一个程序时,一定要检查你是否有像 package_name-devel 这样的开发依赖项。
  3. 在 fedora 上使用 pip 安装时,始终使用 --user。它将在您的家中安装软件包。否则,您可能会与 dnf 包发生冲突。

我也遇到了同样的错误,在终端中尝试了运行以下命令:

sudo dnf install python-pyaudio

在运行上面的命令之后,为了验证你的pyaudio安装是否成功,尝试运行下面的代码: pip install pyaudio 或者您可以检查以下 python 包的列表并通过以下命令找到它:pip list