在 mac 中找不到 pyaudio 检查安装

Could not find pyaudio check installation in mac

我已经使用 brew 安装了 portaudio,并在我的 macos 中使用 pip3 安装了 speechRecognition、pyaudio。 我在 运行 遵循代码

时遇到错误

代码:

    #!/usr/bin/env python
    # Python 3
    import os
    import sys
    import speech_recognition as sr
    r = sr.Recognizer()

    with sr.Microphone() as source:
        print ("say something!");
        audio = r.listen(source)

     try:
          print("google thinks you said" +r.recognize_google(audio))

     except:
          pass

错误:

     Traceback (most recent call last):
     File "test.py", line 8, in <module>
     with sr.Microphone() as source:
     File "/Library/Python/2.7/site-
     packages/speech_recognition/__init__.py", line 79, in __init__
      self.pyaudio_module = self.get_pyaudio()
     File "/Library/Python/2.7/site-
    packages/speech_recognition/__init__.py", line 110, in get_pyaudio
        raise AttributeError("Could not find PyAudio; check 
    installation")
    AttributeError: Could not find PyAudio; check installation

我在我的 nodejs 应用程序中使用 python-shell 运行 宁此 python 脚本。 当我 运行 只有这个脚本与 python3 test.py 一起工作时,它可以工作,但与 python test.py 一起工作时,它不工作。 在我的节点应用程序中它也不起作用。我认为节点正在基本 python 版本 2.7 上执行此脚本。 我使用的是MacOs sierra操作系统

请帮助我提前谢谢:-)

您似乎已经为 python3 安装了软件包,这就是它正在使用它的原因,但是当来自 python2.7 的 运行ning 脚本出现错误时,要解决它,您必须为 python2.7 版本安装相同的软件包。

你能运行命令下面的命令并检查它是否有效。

pip2.7 install pyaudio

安装 2 个东西,

brew install portaudio19-dev python-pyaudio

然后,

pip install pyaudio