为什么在我尝试安装 pyaudio 时出现错误?

Why I get error when I try to install pyaudio?

第一个错误是未安装 Microsoft Visual C++ 14.0,我修复了它...现在,当我尝试安装 pyaudio 时,出现另一个错误。 (我有 Windows 10 个)

我已经安装了所有 visual studio 的软件包...我也尝试使用 wheel 安装,但它说此平台不支持 wheel

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 Studio19\BuildTools\VC\Tools\MSVC.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 Studio19\BuildTools\VC\Tools\MSVC.22.27905\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\VC\Tools\MSVC.22.27905\include" "-IC:\Program Files (
x86)\Windows Kits\NETFXSDK.7.2\include\um" "-IC:\Program Files (x86)\Windows Kits\include.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\include.0.18362.0\shared" "-IC
:\Program Files (x86)\Windows Kits\include.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\include.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\include.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

来自官方docs:

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

话虽这么说,但看到您的错误消息:'portaudio.h': No such file or directory error,我认为您还没有安装此依赖项。

这里的关键部分是 PyAudio 仅提供 python 绑定到 Portaudio 库,但不包括库本身,除非您使用 .whl,但这些不适用于 python 3.7。同样,来自文档(强调我的):

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.

因此您的解决方案是下载并安装缺少的库,或者移动到 python 版本,该版本有包含 Portaudio

的预制轮子