如何解决 PyAudio 安装错误?

How do I solve PyAudio installation error?

所以,我正在寻找一些语音识别项目,我需要使用 PyAudio 库,但是,在 Windows 中安装它时,我收到了一些安装错误。

我使用的安装方法是: pip install pyaudio

当我在cmd中执行命令时,结果是:

   command: 'c:\users\pedro\virtualenvs\pyjarvis\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\pedro\AppData\Local\Temp\pip-install-tbw4bc33\pyaudio_3d715acd64eb45979bf989d5585f978d\setup.py'"'"'; __file__='"'"'C:\Users\pedro\AppData\Local\Temp\pip-install-tbw4bc33\pyaudio_3d715acd64eb45979bf989d5585f978d\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\pedro\AppData\Local\Temp\pip-wheel-9omziclx'
       cwd: C:\Users\pedro\AppData\Local\Temp\pip-install-tbw4bc33\pyaudio_3d715acd64eb45979bf989d5585f978d\
  Complete output (9 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.9
  copying src\pyaudio.py -> build\lib.win-amd64-3.9
  running build_ext
  building '_portaudio' extension
  error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
  ----------------------------------------
  ERROR: Failed building wheel for PyAudio
  Running setup.py clean for PyAudio
Failed to build PyAudio
Installing collected packages: PyAudio
    Running setup.py install for PyAudio ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\pedro\virtualenvs\pyjarvis\scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\pedro\AppData\Local\Temp\pip-install-tbw4bc33\pyaudio_3d715acd64eb45979bf989d5585f978d\setup.py'"'"'; __file__='"'"'C:\Users\pedro\AppData\Local\Temp\pip-install-tbw4bc33\pyaudio_3d715acd64eb45979bf989d5585f978d\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\pedro\AppData\Local\Temp\pip-record-mzmmtmwh\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\pedro\virtualenvs\pyjarvis\include\site\python3.9\PyAudio'
         cwd: C:\Users\pedro\AppData\Local\Temp\pip-install-tbw4bc33\pyaudio_3d715acd64eb45979bf989d5585f978d\
    Complete output (9 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.9
    copying src\pyaudio.py -> build\lib.win-amd64-3.9
    running build_ext
    building '_portaudio' extension
    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

就是这个问题,我该怎么办?

尽管错误显示错误:需要 Microsoft Visual C++ 14.0 或更高版本。您可以尝试从 here.

安装用于 pyaudio 的非官方 python 二进制文件

注意 - 根据您的系统和 python 版本安装 wheel 包。

例如,如果您的系统是 64 位的并且您 运行 python 3.9.x 那么您将必须安装 PyAudio‑0.2.11‑cp39‑cp39‑win_amd64.whl

完成安装后,打开终端并导航到安装 wheel 包的文件夹,然后输入以下命令

pip install your_wheel_package_name.whl