Can't install PyAudio on macOS, getting "library not loaded" error. Portaudio is installed

I tried installing PyAudio on macOS Sonoma, with multiple Python versions. I have portaudio installed with brew, and tried rebooting. When I try to install PyAudio it fails to build wheel with an error, I think the highlight is dyld[14720]: Library not loaded: @rpath/libLTO.dylib.

I searched online, but couldn't find an answer. I have tried python3 -m pip install pyaudio --global-option="build_ext" --global-option="-I/opt/homebrew/include" --global-option="-L/opt/homebrew/lib" and LDFLAGS="-L$(brew --prefix portaudio)/lib" CFLAGS="-I$(brew --prefix portaudio)/include" pip install pyaudio, but those didn't seem to help.

Here is the full output:

Collecting pyaudio
  Using cached PyAudio-0.2.14.tar.gz (47 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (pyproject.toml) ... error
  error: subprocess-exited-with-error

  \C3\97 Building wheel for pyaudio (pyproject.toml) did not run successfully.
  \E2\94\82 exit code: 1
  \E2\95\B0\E2\94\80> [28 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-14-x86_64-cpython-312
      creating build/lib.macosx-14-x86_64-cpython-312/pyaudio
      copying src/pyaudio/__init__.py -> build/lib.macosx-14-x86_64-cpython-312/pyaudio
      running build_ext
      building 'pyaudio._portaudio' extension
      creating build/temp.macosx-14-x86_64-cpython-312
      creating build/temp.macosx-14-x86_64-cpython-312/src
      creating build/temp.macosx-14-x86_64-cpython-312/src/pyaudio
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/include/ "-I/Volumes/Ezsd\C3\A9/Dokumentumok/Programoz\C3\A1s/Python/Megfontol\C3\B3/Megfontol\C3\B3 teszt verzi\C3\B3k/1.2/Teszt verzi\C3\B3k/VirtEnv/include" -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/pyaudio/device_api.c -o build/temp.macosx-14-x86_64-cpython-312/src/Can't install PyAudio on macOS, getting "library not loaded" error. Portaudio is installedpyaudio/device_api.o
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/include/ "-I/Volumes/Ezsd\C3\A9/Dokumentumok/Programoz\C3\A1s/Python/Megfontol\C3\B3/Megfontol\C3\B3 teszt verzi\C3\B3k/1.2/Teszt verzi\C3\B3k/VirtEnv/include" -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/pyaudio/host_api.c -o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/host_api.o
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/include/ "-I/Volumes/Ezsd\C3\A9/Dokumentumok/Programoz\C3\A1s/Python/Megfontol\C3\B3/Megfontol\C3\B3 teszt verzi\C3\B3k/1.2/Teszt verzi\C3\B3k/VirtEnv/include" -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/pyaudio/init.c -o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/init.o
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/include/ "-I/Volumes/Ezsd\C3\A9/Dokumentumok/Programoz\C3\A1s/Python/Megfontol\C3\B3/Megfontol\C3\B3 teszt verzi\C3\B3k/1.2/Teszt verzi\C3\B3k/VirtEnv/include" -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/pyaudio/mac_core_stream_info.c -o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/mac_core_stream_info.o
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/include/ "-I/Volumes/Ezsd\C3\A9/Dokumentumok/Programoz\C3\A1s/Python/Megfontol\C3\B3/Megfontol\C3\B3 teszt verzi\C3\B3k/1.2/Teszt verzi\C3\B3k/VirtEnv/include" -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/pyaudio/main.c -o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/main.o
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/include/ "-I/Volumes/Ezsd\C3\A9/Dokumentumok/Programoz\C3\A1s/Python/Megfontol\C3\B3/Megfontol\C3\B3 teszt verzi\C3\B3k/1.2/Teszt verzi\C3\B3k/VirtEnv/include" -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/pyaudio/misc.c -o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/misc.o
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/include/ "-I/Volumes/Ezsd\C3\A9/Dokumentumok/Programoz\C3\A1s/Python/Megfontol\C3\B3/Megfontol\C3\B3 teszt verzi\C3\B3k/1.2/Teszt verzi\C3\B3k/VirtEnv/include" -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/pyaudio/stream.c -o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/stream.o
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/include/ "-I/Volumes/Ezsd\C3\A9/Dokumentumok/Programoz\C3\A1s/Python/Megfontol\C3\B3/Megfontol\C3\B3 teszt verzi\C3\B3k/1.2/Teszt verzi\C3\B3k/VirtEnv/include" -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/pyaudio/stream_io.c -o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/stream_io.o
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/include/ "-I/Volumes/Ezsd\C3\A9/Dokumentumok/Programoz\C3\A1s/Python/Megfontol\C3\B3/Megfontol\C3\B3 teszt verzi\C3\B3k/1.2/Teszt verzi\C3\B3k/VirtEnv/include" -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/pyaudio/stream_lifecycle.c -o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/stream_lifecycle.o
      clang -bundle -undefined dynamic_lookup -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/device_api.o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/host_api.o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/init.o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/mac_core_stream_info.o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/main.o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/misc.o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/stream.o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/stream_io.o build/temp.macosx-14-x86_64-cpython-312/src/pyaudio/stream_lifecycle.o -L/usr/local/lib -L/usr/lib -L/usr/local/lib/ -lportaudio -o build/lib.macosx-14-x86_64-cpython-312/pyaudio/_portaudio.cpython-312-darwin.so
      dyld[14720]: Library not loaded: @rpath/libLTO.dylib
        Referenced from: <************************************> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
        Reason: tried: '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib' (open() failed with errno=93), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib' (open() failed with errno=93)
      clang: error: unable to execute command: Abort trap: 6
      clang: error: linker command failed due to signal (use -v to see invocation)
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pyaudio
Failed to build pyaudio
ERROR: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects

Does anybody know a solution to this?

Upvotes: 0

Views: 230

Answers (2)

I fixed it by installing macOS on a separate volume, at the setup I restored everything from the old volume, except "Other files". Now all things relating to brew are deleted, so I installed brew, then python and portaudio. The PyAudio installation now works without an error.

Upvotes: 0

Murilo Rocha
Murilo Rocha

Reputation: 155

I had a similar problem with another library. Try another version of python (eg 3.11 or 3.10), it may work.

3.12 is still not fully supported by many libs

Upvotes: 0

Related Questions