2

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.

Philipp K
  • 193
  • 2
  • 18
  • How do you import it? and how do you start that script? do you use virtualenv or similar things? – Torxed Nov 18 '18 at 11:55
  • I was trying to run the [Snowboy](http://docs.kitt.ai/snowboy/) demo in my command line. – Philipp K Nov 18 '18 at 12:43
  • That still doesn't show us (in your question) the few (one) line of code you're using to import and run it. And what your script file is called and so on. And it sounds strange that you have one file called pyaudio.py but nothing else. What's in your `sys.path`? – Torxed Nov 18 '18 at 14:09

4 Answers4

0

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

Legorooj
  • 2,646
  • 2
  • 15
  • 35
  • 1
    There is no PyAudio folder in my site-packages folder. Only a pyaudio.py file – Philipp K Nov 18 '18 at 12:50
  • I'm stumped. I've looked at the (boring) website and docs, and can find no answer. Maybe try putting the file in lib instead? – Legorooj Nov 18 '18 at 23:06
0

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.

0

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.

  • It looks like your answer is specifically tailored to Windows systems (based on your recommendation for `pipwin`). Please note that the question is specifically from someone working on a Mac. – Zoey Hewll Apr 23 '20 at 02:01
  • The first method of installation should work even with Mac. Using the pipwin command is an alternative way of installing only for windows users. – Ahnaf khan Apr 23 '20 at 12:25
0

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.