33

I am having issues installing PyAudio and portaudio.

When I do python -m pip install pyaudio I get this error:

    src/_portaudiomodule.c(29): fatal error C1083: Cannot open include file: 'portaudio.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
Command ""C:\Users\This PC\AppData\Local\Programs\Python\Python37-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\THISPC~1\\AppData\\Local\\Temp\\pip-install-3ock7jqh\\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 C:\Users\THISPC~1\AppData\Local\Temp\pip-record-14pe9p6y\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\

So after looking that error up, I read I need to install portaudio. So I did python -m pip install portaudio and got this error:

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

I have no idea where to go from here now.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
KevinM1990112qwq
  • 715
  • 2
  • 10
  • 23

10 Answers10

76

Try This, CMD as Administrator and run the following:

pip install pipwin
pipwin install pyaudio
hassanzadeh.sd
  • 3,091
  • 1
  • 17
  • 26
18

portaudio is not a Python package, it's a C library that's entirely independent of Python, so you can't install it via pip.

See the PortAudio for website for details on the official way to get it and install it on your platform.

AFAIK, the official way to get it on Windows is to download the source and then follow the instructions in the Tutorial for compiling it yourself. You probably want to build it with the same compiler you use for Python C extensions, although I'm not sure if that's required.

Or, if you're using a third-party package manager like Chocolatey on Windows, there's a good chance it can install PortAudio.

Or, if you use Anaconda or Miniconda for your Python, the conda package manager knows how to install non-Python packages that Python packages depend on, including portaudio.

Finally, there seem to be a number of people providing unofficial pre-compiled PortAudio binaries for Windows. If you search for "portaudio windows binary" or "portaudio windows pre-compiled" you'll find a number of them. I have no idea how well-tested, up-to-date, etc. any of these are.


If you're using Anaconda/Miniconda, you should have used conda install pyaudio rather than pip install pyaudio in the first place. You should really only use pip for packages that aren't available on conda or conda-forge.

If you haven't set up conda-forge yet, you probably want to do that first:

conda config --add channels conda-forge 

And then, this should be all you need:

conda install pyaudio

Unlike the pip package, which just assumes you have portaudio installed properly, the conda package will either automatically install portaudio as a dependency for pyaudio, or tell you why it can't.

abarnert
  • 354,177
  • 51
  • 601
  • 671
  • I am using anaconda. I installed it in the sublime text package manager. So there is a way I can install portaudio with it? – KevinM1990112qwq Aug 23 '18 at 19:04
  • 1
    @KevinM1990112qwq If you're using Anaconda, why did you `pip install pyaudio` instead of `conda install pyaudio`? – abarnert Aug 23 '18 at 19:09
  • I have no ideas, I have just been watching tutorials on getting started in python and that's what it told me to do. – KevinM1990112qwq Aug 23 '18 at 19:12
  • Conda is not working either, possibly not installed even though I did install the package manager in sublime. Man, this ish is confusing. Lol – KevinM1990112qwq Aug 23 '18 at 19:14
  • @KevinM1990112qwq Did you install two or more different copies of Python? `conda` should be on your PATH if you installed Anaconda properly. (And if not, `python` shouldn't be on your PATH, or `pip`, so _nothing_ should be working.) – abarnert Aug 23 '18 at 19:15
  • I am starting over again following everything you have said step by step. I will update in a few moments – KevinM1990112qwq Aug 23 '18 at 19:17
  • Ok, so I installed conda and the channel. I installe pyaudio using conda and it installed portaudio for me perfectly no issues. You ARE THE MAN! Why are not more people talking about this on youtube instead of using PIP? what in the world. This was SO much easier. – KevinM1990112qwq Aug 23 '18 at 19:31
  • Last question though, The environment should still be the same right? Just creating a new py file and importing pyaudio will let the project know the installation from the anaconda and not pip? Or did the anaconda overwrite the pip? – KevinM1990112qwq Aug 23 '18 at 19:32
  • Uhhg also, How do I tell sublime text to use the anaconda version of python and not the normal version of python? – KevinM1990112qwq Aug 23 '18 at 19:51
  • @KevinM1990112qwq Well, Anaconda has only really been amazing for the last year or so. And `pip` plus your distro package manager works very well for everyone—except the 85% of the world that's using Windows and not using a third-party package manager, of course. – abarnert Aug 23 '18 at 20:41
  • For your other questions: The simplest thing to do is to just uninstall your non-Anaconda Python, unless there's some reason you can't. Then there's no issue of "which Python", because there's only one. (Even if you _do_ need two Python setups, you probably want two conda environments—that works even if one environment needs to be Python 3.6, another needs to be Python 2.7, and another needs to be PyPy.) – abarnert Aug 23 '18 at 20:42
  • I installed "conda" package manager for sublime and im using that as the build, im not getting issues or anything, but how do I tell if it is using the anaconda version? – KevinM1990112qwq Aug 23 '18 at 20:44
  • @KevinM1990112qwq Well, `conda` only exists for Anaconda, not normal Python, so that part is definitely right. As for what Python it uses for code highlighting, debugging, etc., I'm not sure if that's a separate setting or what; I don't use Sublime. But it probably has some option to open a Python interactive console or something? If so, you should be able to tell from the banner that's printed at the top of that console. – abarnert Aug 23 '18 at 20:45
  • It's true that `portaudio` is a C library, but that doesn't mean you can't install it with pip. Lots of pip packages contain C libraries. The modern recommended way to deal with this is to use "wheels". You can find unofficial wheels for `pyAudio` here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio . No need to compile source code. – cowlinator Jul 01 '20 at 22:52
12

The official PyAudio 0.2.11 does not support Python 3.7+, and trying to install results in the error C1083: Cannot open include file: 'portaudio.h'.

However, there are unofficial wheels for PyAudio that support 3.7+.

If you are using the official version, you must use Python 3.6 with PyAudio 0.2.11.

See http://people.csail.mit.edu/hubert/pyaudio/

cowlinator
  • 7,195
  • 6
  • 41
  • 61
3

If you get an error when trying to use pipwin to install this, you have to run it through python as windows doesn't recognize pipwin(at least for me)

pip install pipwin
python -m pipwin install pyaudio
Nord
  • 31
  • 3
3

On Ubuntu distributions you can first run

sudo apt install portaudio19-dev

and then reinstall pyaudio with pip again.

Chuk Ultima
  • 987
  • 1
  • 11
  • 21
2

I installed pyaudio on python 3.6.x without problem, but is not working on later versions.

py -m pip install pyaudio

works perfect on 3.6.x or earlier.

Tuhin Mitra
  • 555
  • 7
  • 19
Josué Cano
  • 141
  • 2
  • 6
1

You can install Anaconda install pyaudio using it. You must add Anaconda to path. After installing Anaconda and adding to path then in your command prompt[cmd] type conda install pyaudio. And whala

AYIBO ROBERTS
  • 35
  • 1
  • 4
0

If you are using anaconda then this problem is because your versions are not upgraded.To upgrade all the packages simply run the following command in the terminal.

conda update --all

0

Use the Following Commands

pip install pipwin
pipwin refresh
pipwin install pyaudio
Hamza
  • 132
  • 5
-4

You can install Portaudio with

pip install port audio

you may also need to

pip install ConfigParser

Let me know if it's work.

Dmytro Chasovskyi
  • 3,209
  • 4
  • 40
  • 82