Python包安装问题:PyAudio、PortAudi

2024-04-25 01:16:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我在安装PyAudio和portaudio时遇到问题。

当我这样做python -m pip install pyaudio时,我会得到这个错误:

    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\\2017\\Community\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2
    ----------------------------------------
Command ""C:\Users\This PC\AppData\Local\Programs\Python\Python37-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\THISPC~1\\AppData\\Local\\Temp\\pip-install-3ock7jqh\\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\THISPC~1\AppData\Local\Temp\pip-record-14pe9p6y\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\THISPC~1\AppData\Local\Temp\pip-install-3ock7jqh\pyaudio\

所以在查找错误之后,我读到我需要安装portaudio。所以我做了python -m pip install portaudio并得到了这个错误:

Collecting portaudio
Could not find a version that satisfies the requirement portaudio (from versions: )
No matching distribution found for portaudio

我不知道从现在起要去哪里。


Tags: installpiplocal错误codeerroropenrecord
3条回答

portaudio不是一个Python包,它是一个完全独立于Python的C库,因此不能通过pip安装它。

请参阅PortAudio网站,以获取有关获取并安装到您的平台上的正式方式的详细信息。

AFAIK,在Windows上获得它的官方方法是下载源代码,然后按照Tutorial中的说明自行编译。您可能希望使用与Python C扩展相同的编译器来构建它,尽管我不确定是否需要这样做。

或者,如果您在Windows上使用的是第三方包管理器,比如Chocolatey,那么它很有可能安装PortAudio。

或者,如果在Python中使用Anaconda或Miniconda,conda包管理器知道如何安装Python包所依赖的非Python包,including ^{}

最后,似乎有很多人为Windows提供了非官方的预编译PortAudio二进制文件。如果您搜索“portaudio windows binary”或“portaudio windows pre-compiled”,您将找到其中的一些。我不知道这些有多好测试,更新等等。


如果你使用的是水蟒/小水蟒,你应该首先使用conda install pyaudio,而不是pip install pyaudio。您应该只对condaconda-forge上不可用的包使用pip

如果您还没有设置conda-forge,您可能需要首先设置:

conda config --add channels conda-forge 

然后,这就是你所需要的:

conda install pyaudio

pip包(它只是假设您已经正确安装了portaudio)不同,conda包将自动安装portaudio作为pyaudio的依赖项,或者告诉您为什么不能

您可以使用它安装Anaconda install pyaudio。 你必须把水蟒加到小路上。 安装Anaconda并添加到path之后,在命令提示符[cmd]中键入 conda安装pyaudio。 还有whala

Python 3.7不支持PyAudio 0.2.11,尝试安装会导致错误C1083: Cannot open include file: 'portaudio.h'

必须将Python 3.6与PyAudio 0.2.11一起使用。

http://people.csail.mit.edu/hubert/pyaudio/

相关问题 更多 >