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:\users\upc\appdata\local\programs\python\python37-32\python.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('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'E:\Systmp\usertmp\pip-record-fx3j8t4l\install-record.txt' --single-version-externally-managed --compile
         cwd: E:\Systmp\usertmp\pip-install-yw72dnzm\pyaudio\
    Complete output (15 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    copying src\pyaudio.py -> build\lib.win32-3.7
    running build_ext
    building '_portaudio' extension
    creating build\temp.win32-3.7
    creating build\temp.win32-3.7\Release
    creating build\temp.win32-3.7\Release\src
    D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\upc\appdata\local\programs\python\python37-32\include -Ic:\users\upc\appdata\local\programs\python\python37-32\include "-ID:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-ID:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-ID:\Windows Kits\10\include\10.0.17763.0\ucrt" "-ID:\Windows Kits\10\include\10.0.17763.0\shared" "-ID:\Windows Kits\10\include\10.0.17763.0\um" "-ID:\Windows Kits\10\include\10.0.17763.0\winrt" "-ID:\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcsrc/_portaudiomodule.c /Fobuild\temp.win32-3.7\Release\src/_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:\users\upc\appdata\local\programs\python\python37-32\python.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('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'E:\Systmp\usertmp\pip-record-fx3j8t4l\install-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:\User\Downloads>pip3 install PyAudio-0.2.11-cp37-cp37m-win32.whl
Processing d:\user\downloads\pyaudio-0.2.11-cp37-cp37m-win32.whl
Installing collected packages: PyAudio
Successfully installed PyAudio-0.2.11

 

posted @ 2019-08-07 14:13  狐狸家的鱼  阅读(9383)  评论(0编辑  收藏  举报