【问题标题】:Installing pyaudio with pip in a virtualenv在 virtualenv 中使用 pip 安装 pyaudio
【发布时间】:2016-06-13 00:07:02
【问题描述】:

我正在尝试使用 pip 安装 pyaudio:

pip install pyaudio

在 virtualenv 中,但出现错误:

error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

整个输出:

Collecting pyaudio
  Using cached PyAudio-0.2.9.tar.gz
Building wheels for collected packages: pyaudio
  Running setup.py bdist_wheel for pyaudio ... error
  Complete output from command /home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-GCltlv/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpyR6J73pip-wheel- --python-tag cp27:
  running bdist_wheel
  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
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
  src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
   #include "portaudio.h"
                         ^
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  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 /home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-GCltlv/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-icMIUV-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/include/site/python2.7/pyaudio:
    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
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
    src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
     #include "portaudio.h"
                           ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-GCltlv/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-icMIUV-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/include/site/python2.7/pyaudio" failed with error code 1 in /tmp/pip-build-GCltlv/pyaudio

我做错了什么?我是 virtualenvs 的新手。

*我可以安装其他软件包。我只遇到了 pyaudio 包的错误。

顺便说一下我在环境中:

(ENV) mertyildiran@Corsair:~/Downloads/VirtualEnvironment/vir1/MyProject$

【问题讨论】:

  • 如果你在 ubuntu 上 sudo apt-get install libasound-dev - portaudio.com/docs/v19-doxydocs/compile_linux.html
  • 我在 virtualenv 中,可能这个包没有安装到我的 virtualenv 中。如何将此软件包安装到 virtualenv?通常我可以从 pip 安装 pyaudio。但我在 virtualenv 中。
  • @dm03514 另一方面,有没有办法只使用 pip 进行安装。因为我正在准备一个分发包。

标签: python pip virtualenv pyaudio


【解决方案1】:

这对我有用,我遇到了同样的问题:

如果你想在 virtualenv 中安装 PyAudio,请先从 APT 安装 PortAudio 开发头文件,然后再安装 PyAudio:

sudo apt-get install portaudio19-dev
pip install --allow-unverified=pyaudio pyaudio

https://pyspotify.mopidy.com/en/latest/api/sink/

【讨论】:

  • 这行得通,甚至不需要做 --allow-unverified 标签
  • 非常感谢@Alejandro
  • 只是第一个安装命令行,它对我有用!我在 ubuntu 18.04
【解决方案2】:

某些包需要非 Python 软件的支持,例如共享库。这些不能通过 pip 安装(它们不是 Python 包!)。您通常使用主机的包管理器(apt-getyumdnf 等)将这些 安装在主机上,或者使用 Docker 之类的东西来封装依赖项和你的申请。

在您的情况下,pyaudio 需要许多库,至少包括 portaudio。您需要按照问题的 cmets 中的建议在系统上安装适当的开发包。

【讨论】:

  • 或者你能建议我一个具有相同功能和 pip 安装的不同包吗?
  • 几乎任何提供音频支持的包都需要额外的第三方库。 PyAudio 有一个包,因为那是一个 Python 包。它需要的portaudio 库不是。
  • OK 最后一个问题:pyaudio 或从 pip 安装 pyaudio 的依赖项是否默认随几乎所有 Ubuntu 发行版一起提供?如果是,我会忽略这个问题。
  • portaudio 库在 Ubuntu 上可用,是的,但可能需要显式安装 (apt-get install portaudio19-dev)。您也可以简单地安装 pyaudio 包 (apt-get install python-pyaudio),它会为您处理所有依赖项。
【解决方案3】:

以下步骤对我有用 :) 请通过并尝试

1  sudo apt-get install libasound-dev
2  sudo apt-get install portaudio19-dev
3  pip install pyaudio --user

或者(--user don't work then try python3-pyaudio)

sudo apt-get install python3-pyaudio

【讨论】:

    【解决方案4】:

    在新的 Python 3.0 pyaudio 可以安装在 windows 中使用以下命令: pip3 安装 pyaudio。

    【讨论】:

      【解决方案5】:

      如果你想在windows的虚拟环境中安装pyaudio 首先,您需要在 [https://www.lfd.uci.edu/~gohlke/pythonlibs/] 此处下载 PyAudio-0.2.11-cp37-cp37m-win_amd64.whl 此文件,然后打开命令提示符并转到下载文件所在的路径并键入 pip install PyAudio-0.2.11 -cp37-cp37m-win_amd64.whl

      【讨论】: