Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing PyAudio for Python 3 on OS X

I would like to construct a "Hello, World!" of audio for OS X/Python 3 that populates a buffer with a sine wave and plays it through the speakers.

My basic options are listed in Audio in Python.

Playing Music with Python demonstrates several of these, but it omits details of installation.

I'm trying PyAudio first.

PyAudio has a section on OS X, saying "For Python 3 support, first install MacPython 3.3"

This confuses me greatly. OS X ships with Python. Also, I have used Homebrew to install Python 3. I've never come across the term MacPython, so I'm not sure if what I have is MacPython or not. And if it isn't, then I want to install PyAudio for the Python I currently have. I don't want to have to download some special Python to use it. That would be completely defeating the purpose.

I also tried "pip3 install pyaudio", with the following (negative) results:

⤐  pip3 install pyaudio
 Collecting pyaudio
   Could not find a version that satisfies the requirement pyaudio (from versions: )
   Some externally hosted files were ignored as access to them may be unreliable (use --allow-external pyaudio to allow).
 No matching distribution found for pyaudio
  ✘

 [email protected] ~ /Users/pi:
⤐  pip install --allow-external pyaudio
 You must give at least one requirement to install (see "pip help install")
  ✔

 [email protected] ~ /Users/pi:
⤐  pip install pyaudio --allow-external pyaudio
 Collecting pyaudio
   Could not find a version that satisfies the requirement pyaudio (from versions: )
   Some insecure and unverifiable files were ignored (use --allow-unverified pyaudio to allow).
 No matching distribution found for pyaudio
  ✘

It's frustrating that it is so awkward to even get onto the first rung of the ladder.

How can I correctly install PyAudio for Python 3 on my (up-to-date) OS X? Should I use Homebrew? Should I use pip3?

PS: PyAudio with Homebrew -- I hope I don't have to follow this solution

PPS: Music software written in Python lists a daunting number of possible solution paths -- I'm not at all certain PyAudio is the best path. Is there a better one?

like image 334
P i Avatar asked Jan 20 '26 15:01

P i


1 Answers

Use Homebrew to install the prerequisite portaudio library, then install PyAudio using pip:

brew install portaudio 

pip install pyaudio

Notes:

If not already installed, download Homebrew. pip will download the PyAudio source and build it for your version of Python. Homebrew and building PyAudio also require installing the Command Line Tools for Xcode (more information).

like image 89
王淳龙 Avatar answered Jan 23 '26 04:01

王淳龙



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!