Search code examples
pythonubuntupyaudio

Cannot install PyAudio 0.2.11 in ubuntu 16.04


I downloaded PyAudio 0.2.11 tar file from https://pypi.python.org/pypi/PyAudio and run the following command:

sudo python setup.py install

and I get the following error:

running install

Checking .pth file support in /usr/local/lib/python3.5/dist-packages/
/usr/bin/python3 -E -c pass

TEST PASSED: /usr/local/lib/python3.5/dist-packages/ appears to support .pth files

running bdist_egg

running egg_info

writing top-level names to src/PyAudio.egg-info/top_level.txt

writing src/PyAudio.egg-info/PKG-INFO

writing dependency_links to src/PyAudio.egg-info/dependency_links.txt

reading manifest file 'src/PyAudio.egg-info/SOURCES.txt'

reading manifest template 'MANIFEST.in'

writing manifest file 'src/PyAudio.egg-info/SOURCES.txt'

installing library code to build/bdist.linux-x86_64/egg

running install_lib

running build_py

running build_ext

building '_portaudio' extension

x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.5m -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.5/src/_portaudiomodule.o
src/_portaudiomodule.c:28:20: fatal error: Python.h: No such file or directory

compilation terminated.

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

How can I get it install successfully?

I even tried this "git clone https://people.csail.mit.edu/hubert/git/pyaudio.git" but at the time of compilation it shows the following error:

src/_portaudiomodule.c:28:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

To compile I used this command: sudo python3 setup.py install


Solution

  • Python The first software requirement is Python 2.6, 2.7, or Python 3.3+. This is required to use the library.

    PyAudio (for microphone users) PyAudio is required if and only if you want to use microphone input (Microphone). PyAudio version 0.2.11+ is required, as earlier versions have known memory management bugs when recording from microphones in certain situations.

    If not installed, everything in the library will still work, except attempting to instantiate a Microphone object will raise an AttributeError.

    The installation instructions on the PyAudio website are quite good - for convenience, they are summarized below:

    On Windows, install PyAudio using Pip: execute pip install pyaudio in a terminal.

    On Debian-derived Linux distributions (like Ubuntu and Mint), install PyAudio using APT: execute sudo apt-get install python-pyaudio python3-pyaudio in a terminal. If the version in the repositories is too old, install the latest release using Pip: execute sudo apt-get install portaudio19-dev python-all-dev python3-all-dev && sudo pip install pyaudio (replace pip with pip3 if using Python 3).

    On OS X, install PortAudio using Homebrew: brew install portaudio. Then, install PyAudio using Pip: pip install pyaudio.

    On other POSIX-based systems, install the portaudio19-dev and python-all-dev (or python3-all-dev if using Python 3) packages (or their closest equivalents) using a package manager of your choice, and then install PyAudio using Pip: pip install pyaudio (replace pip with pip3 if using Python 3).

    PyAudio wheel packages for common 64-bit Python versions on Windows and Linux are included for convenience, under the third-party/ directory in the repository root. To install, simply run pip install wheel followed by pip install ./third-party/WHEEL_FILENAME (replace pip with pip3 if using Python 3) in the repository root directory.