Last modified: May 28, 2025 By Alexander Williams
How to Install PyAudio in Python Easily
PyAudio is a Python library for audio processing. It provides bindings for PortAudio. This guide will help you install it.
Table Of Contents
What is PyAudio?
PyAudio allows you to play and record audio. It works on Windows, Mac, and Linux. You can use it to build audio apps.
Prerequisites
Before installing PyAudio, ensure you have Python installed. You can check using python --version
in your terminal.
python --version
Python 3.9.0
Also, install pip if not present. Pip is Python's package manager. It comes with newer Python versions.
Install PyAudio Using Pip
The easiest way to install PyAudio is using pip. Run this command in your terminal.
pip install pyaudio
This will download and install PyAudio. If it fails, you may need additional steps.
Install PyAudio on Windows
On Windows, you might need to install dependencies. Download the PyAudio wheel file first.
Visit https://www.lfd.uci.edu/~gohlke/pythonlibs/. Search for PyAudio. Download the correct version for your Python.
Then install it using pip. Replace the filename with your downloaded file.
pip install PyAudio-0.2.11-cp39-cp39-win_amd64.whl
Install PyAudio on Mac
On Mac, use Homebrew to install dependencies. Run these commands in your terminal.
brew install portaudio
pip install pyaudio
This will install PortAudio first. Then it will install PyAudio.
Install PyAudio on Linux
On Linux, install dependencies using your package manager. For Ubuntu, run this command.
sudo apt-get install python3-pyaudio
For other distros, use their respective package managers. Check their documentation.
Verify PyAudio Installation
After installation, verify it works. Open Python and import PyAudio.
import pyaudio
print(pyaudio.__version__)
0.2.11
If you see the version, PyAudio is installed correctly. If not, check for errors.
Common Installation Errors
You might encounter errors during installation. Here are some common ones and fixes.
Error: PortAudio not found
This means PortAudio is not installed. Install it using your system's package manager.
Error: Microsoft Visual C++ required
On Windows, install Microsoft Visual C++ tools. Download it from Microsoft's website.
Test Audio Recording
Here is a simple script to test audio recording. It records for 5 seconds.
import pyaudio
import wave
# Set parameters
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 5
OUTPUT_FILENAME = "output.wav"
# Initialize PyAudio
audio = pyaudio.PyAudio()
# Start recording
stream = audio.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("Finished recording.")
# Stop recording
stream.stop_stream()
stream.close()
audio.terminate()
# Save to file
wf = wave.open(OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(audio.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
Run this script. It will create an audio file named output.wav.
Conclusion
Installing PyAudio is simple with pip. On some systems, you need extra steps. Always verify the installation.
PyAudio is great for audio apps. You can also check How to Install PyUSB in Python Easily for similar guides.
For more Python libraries, see Install PyBluez in Python Easily and How to Install PyInstaller for Python.