简体   繁体   中英

Why is PyAudio throwing a ModuleNotFoundError when I have it installed?

I've seen similar questions on this site, but none of the solutions have worked. I am using a mac, which gave me some trouble downloading pyaudio. Eventually, I got pyaudio downloaded using pip3 and portaudio installed with homebrew.

I'm coding a virtual assistant, and when I try to use the speech_recognition module, it throws and error telling me that the module cannot find the pyaudio module:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/speech_recognition/__init__.py", line 108, in get_pyaudio
    import pyaudio
ModuleNotFoundError: No module named 'pyaudio'

Yet when I try to run the command pip3 install pyaudio , it tells me that pyaudio is already installed:

Requirement already satisfied: pyaudio in /opt/homebrew/lib/python3.9/site-packages (0.2.11)

How do I fix this? Do I need to somehow move my pyaudio install into another directory? I don't know if this is related, but I've also noticed that whenever I run a terminal command beginning with python3 I get the error zsh: killed python3. I've downloaded python3 and that's what I've been using, as well as using pip3 instead of pip.

looks like the interpreter that you are using might be different, it happened with me once but with a different package, I installed it in a different env and tried to run it in the different env. First make sure that you have activated your virtual enviornment, and there do a pip3 list and check if it shows installed, if it is installed, check the interpreter you are using to run the script, if it's from that venv or not.

在任何情况下都应该有帮助的一件事是在启动 Python 解释器之前在 shell 中执行export PYTHONPATH=$PYTHONPATH:/opt/homebrew/lib/python3.9/site-packages

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM