21

I'm trying to install pyaudio with pip:

pip install pyaudio

In a virtualenv but I'm getting an error:

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

Entire output:

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

What am I doing wrong? I'm new in virtualenvs.

*I'm able to install other packages. I'm facing with an error only for pyaudio package.

By the way I'm in the environment:

(ENV) mertyildiran@Corsair:~/Downloads/VirtualEnvironment/vir1/MyProject$
mertyildiran
  • 6,477
  • 5
  • 32
  • 55
  • 1
    if you're on ubuntu `sudo apt-get install libasound-dev` - http://portaudio.com/docs/v19-doxydocs/compile_linux.html – dm03514 Feb 29 '16 at 19:53
  • I'm in the virtualenv probably this package is not installed to my virtualenv. How can I install this package to virtualenv? Normally I'm able to install pyaudio from pip. But I'm in virtualenv. – mertyildiran Feb 29 '16 at 19:55
  • @dm03514 On the other hand is there a way for install only using pip. Because I'm preparing a package for distribution. – mertyildiran Feb 29 '16 at 19:56

5 Answers5

38

This worked for me, I had the same problem:

if you want to install PyAudio inside a virtualenv, install the PortAudio development headers from APT, then PyAudio:

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

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

edelans
  • 8,479
  • 4
  • 36
  • 45
Alejandro
  • 481
  • 1
  • 4
  • 2
15

Some packages require the support of non-Python software, such as shared libraries. These cannot be installed via pip (they're not Python packages!). You generally install these on the host using your host's package manager (apt-get or yum or dnf, etc...), or you use something like Docker to encapsulate both the dependencies and your application.

In your case, pyaudio requires a number of libraries, including at least portaudio. You will need to install the appropriate development packages on your system, as suggested in the comments on your question.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Or can you suggest me a different package with same functionality and pip installation? – mertyildiran Feb 29 '16 at 20:13
  • Pretty much any package that provides audio support is going to require additional third-party libraries. There is a package for PyAudio because that is a Python package. The `portaudio` library that it requires is not. – larsks Feb 29 '16 at 20:19
  • OK One last question: Are pyaudio or dependencies for installing pyaudio from pip, coming by default with pretty much every Ubuntu distribution or not? I will ignore this issue if so. – mertyildiran Feb 29 '16 at 20:24
  • 13
    The `portaudio` library is *available* for Ubuntu, yes, but it may need to be installed explicitly (`apt-get install portaudio19-dev`). You could also simply install the `pyaudio` package (`apt-get install python-pyaudio`), which would take care of all the dependencies for you. – larsks Feb 29 '16 at 20:30
5

Following steps worked for me :) Please go through and try

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

OR (--user dont work then try python3-pyaudio)

sudo apt-get install python3-pyaudio
Hitesh Patil
  • 141
  • 2
  • 6
0

In new Python 3.0 pyaudio can install in windows use following command: pip3 install pyaudio.

0

If you want to install pyaudio in virtual environment in windows first you need to download PyAudio-0.2.11-cp37-cp37m-win_amd64.whl this file in [https://www.lfd.uci.edu/~gohlke/pythonlibs/] here and then open command prompt and go to the path where your downloaded file located and type pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl

sanyassh
  • 8,100
  • 13
  • 36
  • 70