Search code examples
pythonpython-3.xvisual-studiopyaudio

Why I get error when I try to install pyaudio?


The first error whas Microsoft Visual C++ 14.0 is not installed and I fixed it... Now when I try to install pyaudio I get another error. (I've Windows 10)

I've installed all visual studio's packages... I tried also to use wheel installation but it says that wheel is not supported on this platform

Collecting pyaudio
  Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Installing collected packages: pyaudio
  Running setup.py install for pyaudio ... error
    Complete output from command C:\Users\Hp\PycharmProjects\Jarvis\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Hp\\AppData\\Local\\Temp\\pip-install-r8s
c6ih0\\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\Hp\AppDa
ta\Local\Temp\pip-record-zm1aoh_y\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\Hp\PycharmProjects\Jarvis\venv\include\site\python3.7\pyaudio:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.7
    copying src\pyaudio.py -> build\lib.win-amd64-3.7
    running build_ext
    building '_portaudio' extension
    creating build\temp.win-amd64-3.7
    creating build\temp.win-amd64-3.7\Release
    creating build\temp.win-amd64-3.7\Release\src
    C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.22.27905\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -DMS_WIN64=1 -IC:\Users\Hp\PycharmPro
jects\Jarvis\venv\include -IC:\Users\Hp\AppData\Local\Programs\Python\Python37\include -IC:\Users\Hp\AppData\Local\Programs\Python\Python37\include "-IC:\Program Files (x86)\Microsoft Visua
l Studio\2019\BuildTools\VC\Tools\MSVC\14.22.27905\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.22.27905\include" "-IC:\Program Files (
x86)\Windows Kits\NETFXSDK\4.7.2\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC
:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.1
8362.0\cppwinrt" /Tcsrc/_portaudiomodule.c /Fobuild\temp.win-amd64-3.7\Release\src/_portaudiomodule.obj
    _portaudiomodule.c
    C:\Users\Hp\AppData\Local\Programs\Python\Python37\include\pyconfig.h(117): warning C4005: 'MS_WIN64': ridefinizione macro
    src/_portaudiomodule.c: note: vedere la precedente definizione di 'MS_WIN64'
    src/_portaudiomodule.c(29): fatal error C1083: Non Š possibile aprire il file inclusione: 'portaudio.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.22.27905\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2

Solution

  • From the official docs:

    To build PyAudio from source, you will also need to build PortAudio v19

    That being said and seeing your error message: 'portaudio.h': No such file or directory error, I think you have not installed this dependency.

    The key part here is that PyAudio only provides python bindings to the Portaudio library, but does not include the library itself, unless you install using a .whl, but these are not available for python 3.7. Again, from the docs (emphasis mine):

    pip will fetch and install PyAudio wheels (prepackaged binaries). Currently, there are wheels compatible with the official distributions of Python 2.7, 3.4, 3.5, and 3.6. For those versions, both 32-bit and 64-bit wheels are available.

    So your solution is to either download and install the missing library, or move to a python version for which there are pre built wheels that include Portaudio