【问题标题】:How to install PyAudio 0.2.11 Fedora如何安装 PyAudio 0.2.11 Fedora
【发布时间】:2018-04-10 15:46:55
【问题描述】:

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

“需要 PyAudio 0.2.11 或更高版本(找到版本 0.2.9)”

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

每当我尝试做时

pip 安装 pyaudio

我收到以下错误:

pyaudio 的构建*失败 为 pyaudio 运行 setup.py clean 无法构建 pyaudio 安装收集的包:pyaudio 为 pyaudio 运行 setup.py install ... 错误 命令的完整输出 /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: 运行安装 运行构建 运行 build_py 创建构建 创建 build/lib.linux-x86_64-2.7 复制 src/pyaudio.py -> build/lib.linux-x86_64-2.7 运行 build_ext 构建“_portaudio”扩展 创建 build/temp.linux-x86_64-2.7 创建 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:错误:/usr/lib/rpm/redhat/redhat-hardened-cc1:没有这样的文件或目录 错误:命令“gcc”失败,退出状态为 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 " 失败,错误代码 1 在 /tmp/pip-build-ZiuxD3/pyaudio/

【问题讨论】:

    标签: python speech-recognition fedora pyaudio


    【解决方案1】:

    你需要:

    sudo dnf install portaudio-devel redhat-rpm-config
    

    接下来就可以安装pyaudio了。

    pip install --user pyaudio
    

    注意:

    1. yum 已弃用,请改用 dnf。
    2. 当您看到有关程序的编译/构建时,请始终检查您是否具有 devel 依赖项,例如 package_name-devel。
    3. 在fedora 上使用pip 安装时,始终使用--user。它将在您的家中安装软件包。否则,您可能会与 dnf 包产生冲突。

    【讨论】:

    • 第一步有效,但第二步我得到了同样的错误。
    • 你首先需要这个:redhat-rpm-config。但是,portaudio-devel 之后是必要的。否则,您将遇到另一个类似的错误。
    • 谢谢!有效。我第一次没有看到redhat-rpm-config。
    【解决方案2】:

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

    sudo dnf install python-pyaudio
    

    运行上述命令后,要验证您的pyaudio安装是否成功,请尝试运行以下代码: pip install pyaudio 或者您可以查看以下 python 包的列表并通过以下命令找到它:pip list

    【讨论】: