Preloader
Ubuntu
  • Estimated reading time: 2 Minutes

How to solve installation error of PyAudio in Ubuntu 18.04 (fatal error: 'portaudio.h' file not found)

Usually, you will be able to install PyAudio with PIP using the following command:

pip install PyAudio

Pitifully, in some distributions of Ubuntu, you will face an exception about a failure when building the wheel for pyaudio. According to the Python Packaging Index’s description, a wheel *is designed to contain all the files for a PEP 376 compatible install in a way that is very close to the on-disk format.

Error

The error output when you try to install the package will be:

pip install pyaudio
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 /Users/kj/Desktop/ml/gui/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/vd/8zl261fj35j8pst5659glmjc0000gn/T/pip-build-gj9ny3f9/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 /var/folders/vd/8zl261fj35j8pst5659glmjc0000gn/T/pip-45sl0b3v-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/kj/Desktop/ml/gui/include/site/python3.6/pyaudio:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.12-x86_64-3.6
    copying src/pyaudio.py -> build/lib.macosx-10.12-x86_64-3.6
    running build_ext
    building '_portaudio' extension
    creating build/temp.macosx-10.12-x86_64-3.6
    creating build/temp.macosx-10.12-x86_64-3.6/src
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -DMACOSX=1 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/Users/kj/Desktop/ml/gui/include -I/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c src/_portaudiomodule.c -o build/temp.macosx-10.12-x86_64-3.6/src/_portaudiomodule.o
    src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
    #include "portaudio.h"
             ^~~~~~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1

The error is basically caused by the missing portaudio.h file in the system. PortAudio is a free, cross-platform, open-source, audio I/O library.

Solution

You can fix this exception installing the dev portaudio package and pyaudio with the following command in Ubuntu:

sudo apt-get install portaudio19-dev python-pyaudio

Finally install the package again with the command:

pip install PyAudio

And you should be able to install it properly without an issue !

Happy coding !

Share:
Carlos Delgado

Carlos Delgado

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Related articles
How to install the latest version of Git in Ubuntu 20.04
26 Aug, 2022
  • Estimated reading time: 1 Minute
How to install aapanel in Ubuntu 20.04
14 Aug, 2022
  • Estimated reading time: 1 Minute
How to install Prometheus Node Exporter on Ubuntu 20.04
27 Mar, 2022
  • Estimated reading time: 4 Minutes
How to extract the content of a tar.gz file in Ubuntu
16 Nov, 2021
  • Estimated reading time: 1 Minute
How to install Anaconda in Ubuntu 20.04
6 Nov, 2021
  • Estimated reading time: 3 Minutes
How to install Elasticsearch 7 in Ubuntu 20.04
29 Apr, 2021
  • Estimated reading time: 5 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.