使用pip在virtualenv中安装pyaudio

时间:2016-02-29 19:44:34

标签: python pip virtualenv pyaudio

我正在尝试使用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$

5 个答案:

答案 0 :(得分:31)

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

如果你想在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/

答案 1 :(得分:12)

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

在您的情况下,pyaudio需要许多库,至少包括portaudio。您需要在系统上安装相应的开发包,如问题评论中所述。

答案 2 :(得分:2)

以下步骤为我工作:)请仔细阅读

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

OR( - 用户不用,然后尝试python3-pyaudio)

sudo apt-get install python3-pyaudio

答案 3 :(得分:0)

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

答案 4 :(得分:0)

如果要在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