Fixing portaudio.h: No such file or directory compilation terminated.

portaudio.h: No such file or directory compilation terminated. is an issue which occurs when you try to install pyaudio before installing portaudio and sometimes it happens when the portaudio installation is faulty.

In this blog post I will get into what occurs when you get this error and how we can get rid of it with a main solution, I will also try to present other solutions if possible.

Explaining the Error : portaudio.h: No such file or directory compilation terminated.

This is an issue which occurs when you try to install pyaudio before installing portaudio and sometimes it happens when the portaudio installation is faulty.

Your error message should match the one bellow. We want to avoid confusion by not mixing between error messages.

                                                                       #
Collecting pyaudio
  Downloading PyAudio-0.2.11.tar.gz
Installing collected packages: pyaudio
  ....
    src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
    compilation terminated.
                                                                       #

Bellow I make my best attempt at solving the error and present multiple possible solutions.

Solution 1 : install portaudio before you install pyaudio

In many cases, before you install pyaudio you should start by installing portaudio first.

You can use brew to install portaudio using the command bellow.

                                                                       #
brew install portaudio
                                                                       #

The second step is to install pyaudio using pip3 or pip depending on your case.

                                                                       #
pip3 install pyaudio
                                                                       #

I hope this solution helped you solve the issue, congratulations. If that is not the case please try the following solution.

Solution 2 : install both portaudio and pyaudio using one command

You can actually install both portaudio and pyaudio using one command. If you have the most recent os ersion try the command bellow.

                                                                       #
sudo apt install portaudio19-dev python3-pyaudio
                                                                       #

If the command above does not solve the issue try adding python-pyaudio to the command like in the command bellow.

                                                                       #
sudo apt-get install portaudio19-dev python-pyaudio python3-pyaudio
                                                                       #

I hope one of these two solutions helped you solve the issue, congratulations If the issue is gone.

Summing-up

Finally, we are at the end of this article, I hope this article has been helpful, I hope you solved your problem, coding can be hard when you have a lot of confusing errors here and there.

Thank you for reading, keep learning and keep coding, cheers. If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/