在Google Colab中无法安装Pyaudio。

10

我尝试运行 pip install PyAudio,但是出现了以下错误:

  Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: PyAudio
  Building wheel for PyAudio (setup.py) ... error
  ERROR: Failed building wheel for PyAudio
  Running setup.py clean for PyAudio
Failed to build PyAudio
Installing collected packages: PyAudio
    Running setup.py install for PyAudio ... error
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-o_0h_bmo/PyAudio/setup.py'"'"'; __file__='"'"'/tmp/pip-install-o_0h_bmo/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 /tmp/pip-record-8_ovxdkm/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.
3个回答

20

你只需要从apt安装中删除libav-tools并再次运行此命令即可。

!apt install libasound2-dev portaudio19-dev libportaudio2 libportaudiocpp0 ffmpeg

然后执行:

!pip install PyAudio

这样就能够进行安装了。


我在哪里可以删除 libav-tools? - Abdun Noor Polok
1
只需运行我分享的命令,您就可以安装@AbdunNoorPolok。 - Prabhat Kumar Sahu

2
假设您在Colab上运行默认的Python(当前版本为3.7.10)。在这种情况下,PyAudio是一个旧的、可能未维护的软件包,并且没有适用于Python 3.7的wheel。
官方文档中提到:

目前,有与Python 2.7、3.4、3.5和3.6官方发行版兼容的wheel。对于这些版本,都有32位和64位的wheel可用。

你有两种解决方法:
  • 选择另一个类似的软件包。请查看Python Sound Device

  • 将您的Colab环境降级到Python 3.6。请查看这里的说明。

如果我是您,我会选择第一种方法,因为您应该使用更新的Python版本。此外,主观上,Python Sound Device具有更好的API。

0

如果您在Google Colab上安装PyAudio时遇到问题,很可能是平台和库之间的兼容性问题。以下是您可以尝试的几件事:

尝试安装旧版本的PyAudio:

!pip install pyaudio==0.2.11

使用其他安装方法安装PyAudio,例如从源代码构建:

!apt-get install -y libasound-dev
!pip install pyaudio

如果上述步骤无效,您可以尝试使用其他音频处理库,例如PySoundFile或pydub。
请记住,Google Colab是一个基于云的平台,某些库可能与其环境不完全兼容。如果无法安装PyAudio,则建议尝试使用其他平台或环境,在那里您可以更好地控制安装过程。
另外一种方法。
pip install pipwin
pipwin install pyaudio

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