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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章