How to install pyaudio on mac when there is some error


If you’re encountering issues installing PyAudio on a Mac, the solution might involve a few steps, particularly if you’re seeing error messages like:

  • -bash: pip: command not found
  • fatal error: 'portaudio.h' file not found

Here’s a succinct guide to solving these installation problems:

  1. Error when trying pip install pyaudio:
    You might see -bash: pip: command not found. This suggests that pip is not installed or recognized in your environment.

  2. Error when trying pip3 install pyaudio:
    The error message fatal error: 'portaudio.h' file not found indicates that the PortAudio library, which PyAudio depends on, is not properly installed or recognized.

  3. If you’ve already installed PortAudio via Homebrew (brew install portaudio) but still encounter issues, it’s possible that there’s a mismatch or an issue with how the library is being recognized by the PyAudio installer.

To solve these issues, follow these steps:

  1. Ensure Xcode is installed: First, make sure you have Xcode installed on your Mac, as it includes command-line tools needed for compiling software.

  2. Install Xcode Command Line Tools: Run xcode-select --install in your terminal to install any missing command-line tools.

  3. Reinstall PortAudio: Remove the existing PortAudio installation (if any) and reinstall it to ensure it’s properly set up.

    • brew remove portaudio
    • brew install portaudio
  4. Install PyAudio: With PortAudio correctly installed, you should now be able to install PyAudio without encountering the previous errors.

    • pip3 install pyaudio

This sequence of steps addresses the common issues faced when installing PyAudio on a Mac, especially related to missing dependencies and command-line tools.


Author: robot learner
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint policy. If reproduced, please indicate source robot learner !
  TOC