'PyAudio : AttributeError: 'module' object has no attribute 'PyAudio'
Today I installed Pyaudio by using instruction on http://people.csail.mit.edu/hubert/pyaudio/ and trying to run some examples like this one.
import pyaudio
import wave
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print("* done recording")
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
and when I'm trying to run it
AttributeError: 'module' object has no attribute 'PyAudio'
How can this be?
Solution 1:[1]
Did you name your example file pyaudio.py? When I did, I got the same error. In this case just rename your working file.
Solution 2:[2]
I have never used PyAudio, but I have used SpeechRecogition, and in that, you may have to use PortAudio, based off of operating system. Download homebrew(brew) first.
Debian Linux
$ brew install portaudio
$ pip install pyaudio
MacOS
$ brew install portaudio
$ pip install pyaudio
If a windows user, then I don't know the answer.
Solution 3:[3]
try typing in terminal
pip install pyaudio
Solution 4:[4]
Your version of python may not be compatible with pyaudio(i.e pyaudio is not available on python 3). If you want to install pyaudio on python 3 using pip open this link. NOTE: This is for windows os only
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio
Click on the version you want to download
for tutorials on the installation use this link: https://www.youtube.com/watch?v=-AzGZ_CHzJk start watching from 3min Pyaudio should when you are done with this
Solution 5:[5]
You can download wheel file from given link below and then install it by using "pip install 'wheel file name with their extension'"
Visit to learn more about Python
Click on the version you want to download
Solution 6:[6]
pyaudio is difficult to install on some platforms. On linux it fails because it wants a different compiler. Anacoda will install a compiled wheel; so you can do a conda install pyaudio. You can also do a sudo apt install python-pyaudio. I don't know about windows or mac.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | double-beep |
| Solution 2 | Community |
| Solution 3 | Virtual Dreamer |
| Solution 4 | AYIBO ROBERTS |
| Solution 5 | Nitesh Kumar |
| Solution 6 | Micheal Bee |
