Python 无法安装PyAudio问题

一、错误与原因

Windows上没有用于Python 3.7的轮子(预构建包)(有一个用于Python 2.73.43.6),因此需要在PC上准备构建环境以使用此包。因为有些软件包很难在Windows上构建,所以找到3.7的轮子更容易一些。

这是安装时报的错:

> pip3 install pyaudio
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
    ERROR: Command errored out with exit status 1:
     command: 'c:usersupcappdatalocalprogramspythonpython37-32python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'E:\Systmp\usertmp\pip-install-yw72dnzm\pyaudio\setup.py'"'"'; __file__='"'"'E:\Systmp\usertmp\pip-install-yw72dnzm\pyaudio\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'E:Systmpusertmppip-record-fx3j8t4linstall-record.txt' --single-version-externally-managed --compile
         cwd: E:Systmpusertmppip-install-yw72dnzmpyaudio
    Complete output (15 lines):
    running install
    running build
    running build_py
    creating build
    creating buildlib.win32-3.7
    copying srcpyaudio.py -> buildlib.win32-3.7
    running build_ext
    building '_portaudio' extension
    creating build	emp.win32-3.7
    creating build	emp.win32-3.7Release
    creating build	emp.win32-3.7Releasesrc
    D:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023inHostX86x86cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:usersupcappdatalocalprogramspythonpython37-32include -Ic:usersupcappdatalocalprogramspythonpython37-32include "-ID:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023ATLMFCinclude" "-ID:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023include" "-IC:Program Files (x86)Windows KitsNETFXSDK4.6.1includeum" "-ID:Windows Kits10include10.0.17763.0ucrt" "-ID:Windows Kits10include10.0.17763.0shared" "-ID:Windows Kits10include10.0.17763.0um" "-ID:Windows Kits10include10.0.17763.0winrt" "-ID:Windows Kits10include10.0.17763.0cppwinrt" /Tcsrc/_portaudiomodule.c /Fobuild	emp.win32-3.7Releasesrc/_portaudiomodule.obj
    _portaudiomodule.c
    src/_portaudiomodule.c(29): fatal error C1083: 无法打开包括文件: “portaudio.h”: No such file or directory
    error: command 'D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:usersupcappdatalocalprogramspythonpython37-32python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'E:\Systmp\usertmp\pip-install-yw72dnzm\pyaudio\setup.py'"'"'; __file__='"'"'E:\Systmp\usertmp\pip-install-yw72dnzm\pyaudio\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'E:Systmpusertmppip-record-fx3j8t4linstall-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

二、解决方法

我也是搜索了一下,参照stackoverflow这个回答

  • 打开python终端,在一个.py文件右键,选择Edit with IDLE->Edit with IDLE3.7(32 bit)打开,然后使用F5快速启动,即可看到你的python所有基本信息,比如我的版本是3.7.4,32位的
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
  • 下载你所需的轮子,根据你的信息下载相匹配的轮子,比如如果是64 bit (AMD64),就要下载PyAudio‑0.2.11‑cp37‑cp37m‑win_amd64.whl,而我需要下载的是上一个PyAudio‑0.2.11‑cp37‑cp37m‑win32.whl,以下圈出的是与64 bit(AMD64)适用的
    在这里插入图片描述
  • 找到相对应的轮子下载后,在轮子所在文件夹内安装
pip3 install PyAudio-0.2.11-cp37-cp37m-win32.whl

# 出现以下信息代表安装成功
D:UserDownloads>pip3 install PyAudio-0.2.11-cp37-cp37m-win32.whl
Processing d:userdownloadspyaudio-0.2.11-cp37-cp37m-win32.whl
Installing collected packages: PyAudio
Successfully installed PyAudio-0.2.11
原文地址:https://www.cnblogs.com/suRimn/p/11314938.html