简体   繁体   中英

Pyaudio module not found despite being installed

I'm trying to work with the pyaudio package but for some reason my command line keeps telling me ImportError: No module named pyaudio

If I run

python3 -m pip install pyaudio

I get

Requirement already satisfied: pyaudio in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.2.11)

I have tried some approaches that I found elsewhere but nothing worked so far. Any advice is appreciated. I'm working on a Mac if that matters.

To import PyAudio look in your lib/site-packages and see if the PyAudio folder is spelt PyAudio or pyaudio, and try the corresponding import:

import PyAudio # folder spelt PyAudio
import pyaudio # folder spelt pyaudio

Or use a try statement

pyaudio module needs a visual studio C++ build for versions 3.7 or greater . However for version 3.5 it can be easily installed with

pip install pyaudio

This will install pyaudio with no errors.

PyAudio seems to not work simply for Python versions above 3.7. I have the same problem but solved it. If you have not downloaded PyAudio, you have to go to https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio and install the version compatible with your python. Then you have to install the file with pip command in terminal in the folder you have downloaded the file such as: pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl.

If this installation doesn't work try this: pip install pipwin pipwin install pyaudio

Now if you have installed PyAudio but it's still not working, first download the build tools for Vs Code from https://visualstudio.microsoft.com/visual-cpp-build-tools/ . Now follow the first few instructions from https://code.visualstudio.com/docs/cpp/config-msvc . to configure your VsCode with the build tools.

Just had the same problem.

> python3 --version
Python 3.9.x
> pip3 install pyaudio
Requirement already satisfied: pyaudio in ~/Library/Python/3.8/lib/python/site-packages (0.2.11)

Had inadvertently updated python to 3.9, but pip3 was still installing in 3.8. Solution for my purposes was to uninstall python 3.9 and go back to 3.8.

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