PortAudio: “fatal error C1083: Cannot open include file: ‘portaudio.h’: No such file or directory” In Python

PortAudio: “fatal error C1083: Cannot open include file: ‘portaudio.h’: No such file or directory” In Python is a popular error which occurs when you are trying to install a package which is not a Python package.

In this article I am going to explain why this error is happening and how developers can avoid this issue, also I am going to detail how I solved the error and how you can solve it if the main solution does not work for your case.

Describing PortAudio: “fatal error C1083: Cannot open include file: ‘portaudio.h’: No such file or directory” In Python

All the chaos started when I wanted to install PyAudio using pip in Python.

After running the code bellow, an error appeared, this is the code

                                                                       #
python -m pip install pyaudio
                                                                       #

This is exactly the error I get

                                                                       #
src/_portaudiomodule.c(29): fatal error C1083: Cannot open include file: 'portaudio.h': No such file or directory
    ----------------------------------------
install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\THISPC~1\AppData\Local\Temp\pip-install-3ock7jqh\pyaudio\
                                                                       #

Solving the error can only be achieved by installing PortAudio using pip, bellow us an example of the code

                                                                       #
python -m pip install portaudio
                                                                       #

Then I get another error

                                                                       #
Collecting portaudio
Could not find a version that satisfies the requirement portaudio (from versions: )
No matching distribution found for portaudio
                                                                       #

At this point I was ready to give up until I found the solution and removed the error, the solution is described in detail in the section bellow.

Solution 1 : install PortAudio using conda (PortAudio is a C library)

The key to solve the error is understanding that PortAudio is not a Python package it is actually a C library, you can not install a C library using pip.

Go to the PortAudio official page and download the source then compile it yourself.

If you do not want to do that yourself you can use a 3rd party package manager like chocolatey on windows, you can install PortAudio that way.

The other way is to install anaconda on your machine, anaconda knows how to install PortAudio.

But first you need to setup conda-forge after installing Anaconda, you can do it by running the code.

                                                                       #
conda config --add channels conda-forge 
                                                                       #

Now you can with one line of code install PortAudio using conda.

                                                                       #
conda install pyaudio
                                                                       #

Now anaconda will install both PyAudio and PortAudio.

Solution 2 : use pipwin to install pyaudio

If the solution above did not work for you do not worry, I have another more powerful solution for you.

This one is actually way more simple.

Step 1 – Run CMD as an Administrator.

Step 2 – Install pipwin using pip as you can see in the code bellow.

                                                                       #
pip install pipwin
                                                                       #

Step 3 – Install pyaudio using pipwin as you can see in the code bellow.

                                                                       #
pipwin install pyaudio
                                                                       #

If you get a HTTP 404 error make sure to run the code bellow before installing PyAudio

                                                                       #
pipwin refresh
                                                                       #

Solution 3 : install pyaudio for the correct python version

If you have Python 3.6 it seems that you can install PyAudio with no problems , but you can not do that in the later versions of Python.

Just run the code bellow and everything will be fine.

                                                                       #
py -m pip install pyaudio
                                                                       #

I hope this solution worked for you, I wish you good luck.

Summing-up

The end of this article is here, please make sure to support the team by clicking the Kofi button, it is the red button on the top of this page, it is for donations and will help us help more developers in our error solving journey.

Please 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/