无法安装pyAudio包

3

我正在开发语音识别程序,但无法安装pyAudio。

我已经安装了Microsoft Visual C++ 14.0.0,但仍然出现另一个错误。我不知道问题出在哪里,请帮我解决。

 ERROR: Command errored out with exit status 1:
         command: 'c:\users\udit\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv\[0\] = '"'"'C:\\Users\\udit\\AppData\\Local\\Temp\\pip-install-68co_fpl\\pyaudio\\setup.py'"'"'; __file__='"'"'C:\\Users\\udit\\AppData\\Local\\Temp\\pip-install-68co_fpl\\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\udit\AppData\Local\Temp\pip-record-ih2tcx4k\install-record.txt' --single-version-externally-managed --compile
             cwd: C:\Users\udit\AppData\Local\Temp\pip-install-68co_fpl\pyaudio\
        Complete output (16 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
        b'\\\x00C\x00o\x00m\x00m\x00o\x00n\x00 \x00w\x00a\x00s\x00 \x00u\x00n\x00e\x00x\x00p\x00e\x00c\x00t\x00e\x00d\x00 \x00a\x00t\x00 \x00t\x00h\x00i\x00s\x00 \x00t\x00i\x00m\x00e\x00.\x00\r\x00\n\x00'
        creating build\temp.win32-3.7
        creating build\temp.win32-3.7\Release
        creating build\temp.win32-3.7\Release\src
        C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Bin\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Ic:\users\udit\appdata\local\programs\python\python37-32\include -Ic:\users\udit\appdata\local\programs\python\python37-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\Include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" /Tcsrc/_portaudiomodule.c /Fobuild\temp.win32-3.7\Release\src/_portaudiomodule.obj
        _portaudiomodule.c
        src/_portaudiomodule.c(29): fatal error C1083: Cannot open include file: 'portaudio.h': No such file or directory
        error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\Bin\\cl.exe' failed with exit status 2
        ----------------------------------------
    ERROR: Command errored out with exit status 1: 'c:\users\udit\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv\[0\] = '"'"'C:\\Users\\udit\\AppData\\Local\\Temp\\pip-install-68co_fpl\\pyaudio\\setup.py'"'"'; __file__='"'"'C:\\Users\\udit\\AppData\\Local\\Temp\\pip-install-68co_fpl\\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\udit\AppData\Local\Temp\pip-record-ih2tcx4k\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

可能是Python软件包安装问题:PyAudio,PortAudio的重复。 - Dinko Pehar
尝试以管理员身份运行此CMD:pip install pipwin / pipwin install pyaudio。 - hassanzadeh.sd
4个回答

4

以下是在 Microsoft Windows 上安装的注意事项:

pip 将获取并安装 PyAudio wheels (预打包二进制文件)。目前,有与 Python 2.7、3.4、3.5 和 3.6 官方发行版兼容的 wheels。对于这些版本,32 位和 64 位的 wheels 都可用。

您正在使用不兼容 PyAudio 的 Python 3.7。但是...

编辑:

如用户 @Dalen 所述,pyAudio 有预构建的二进制文件 (.exe 文件)。我从他们在文档中提到的存档中安装了它,但导入 pyAudio 后输出如下:

Windows python

此站点上有适用于 Windows 的非官方二进制文件: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio

下载适当的文件并安装


我在anaconda中使用python 3.7成功运行了pyaudio 0.2.11,没有任何问题。虽然它尚未得到支持,但这并不矛盾于可以运行的事实。 - user11563547
是的,它可以工作。只需从https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio下载适当的.whl文件,然后安装它。然后你就可以开始了! - Fatihd

1

下载适用于Windows的二进制安装程序,只需安装PyAudio软件包即可,不需要繁琐的步骤。

PyAudio是基于portaudio库构建的,需要安装portaudio。二进制安装程序附带了预编译版本的portaudio作为动态链接库,无需寻找和编译源代码。

PyAudio是一个很棒的库,希望您喜欢使用它。


他通过 pip 安装要比从源代码编译容易得多。 - Dinko Pehar
1
@DinkoPehar:pip会下载软件包(源代码版本),然后运行其setup.py文件,对于PyAudio而言,它会从源代码编译。通常情况下,它不会检查Python版本是否兼容。如果您不知道,二进制安装程序是一个*.exe或*.msi安装程序,只需要点击几次愚蠢的“下一步”按钮即可完成安装。 - Dalen
我一开始没有理解你所指的内容。我以为你是让他下载 portaudio 的预编译版本,然后以某种方式安装 pyAudio,但实际上你是指 http://people.csail.mit.edu/hubert/pyaudio/packages/ 上列出的 .exe 文件,如果我没有误解的话。如果是这样的话,我将把你的回答追加到我的回答中。 - Dinko Pehar
@DinkoPehar:没错!一开始PyAudio有官方发布的二进制安装程序(如果我没记错的话),但后来就停止了。不过这个次要来源应该是安全的。 - Dalen
让我们在聊天中继续这个讨论 - Dinko Pehar
显示剩余2条评论

1
pip install pipwin

pipwin install pyaudio

在提示符中尝试这些命令。它不需要任何手动下载或搜索等。 pipwin是Windows上pip的补充工具。它能够安装由Christoph Gohlke提供的非官方Python软件包二进制文件。


0

错误信息中的关键信息是“无法打开包括文件:'portaudio.h':没有那个文件或目录”

因此,您应该在谷歌上搜索它,您会发现在stackoverflow上有一个答案: https://dev59.com/91QK5IYBdhLWcg3wXeqM#52191687

当前版本的PyAudio 0.2.11不支持Python 3.7


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接