pyaudioportaudio

Problems installing PyAudio


I am currently trying to install PyAudio to use SpeechRecognition in python. I get the error fatal error: portaudio.h: No such file or directory (entire error:

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

× Building wheel for PyAudio (pyproject.toml) did not run successfully.
│ exit code: 1
╰─\> \[18 lines of output\]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-311
creating build/lib.linux-x86_64-cpython-311/pyaudio
copying src/pyaudio/__init__.py -\> build/lib.linux-x86_64-cpython-311/pyaudio
running build_ext
building 'pyaudio.\_portaudio' extension
creating build/temp.linux-x86_64-cpython-311
creating build/temp.linux-x86_64-cpython-311/src
creating build/temp.linux-x86_64-cpython-311/src/pyaudio
x86_64-unknown-linux-gnu-gcc -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -pipe -g -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -O2 -pipe -g -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -fPIC -I/usr/local/include -I/usr/include -I/usr/include/python3.11 -I/usr/include/x86_64-linux-gnu/python3.11 -c src/pyaudio/device_api.c -o build/temp.linux-x86_64-cpython-311/src/pyaudio/device_api.o
src/pyaudio/device_api.c:9:10: fatal error: portaudio.h: No such file or directory
9 | #include "portaudio.h"
|          ^\~\~\~\~\~\~\~\~\~\~\~\~
compilation terminated.
error: command '/usr/bin/x86_64-unknown-linux-gnu-gcc' 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
ERROR: Could not build wheels for PyAudio, which is required to install pyproject.toml-based projects\`.

I installed portaudio19-dev, and it didn't do anything. I can find the file under /usr/include/portaudio.h, but, again, it doesn't find it. all dependencies for portaudio are installed as well. I tried both pip install PyAudio and pip install --user PyAudio. Neither work. I am on Linux Mint 21.3 x86_64 and use Pycharm 2024.1.1. Hope someone could help.

I installed portaudio19-dev, and it didn't do anything. I can find the file under /usr/include/portaudio.h, but, again, it doesn't find it. all dependencies for portaudio are installed as well. I tried both pip install PyAudio and pip install --user PyAudio. Neither work. I am on Linux Mint 21.3 x86_64 and use Pycharm 2024.1.1. Hope someone could

Edit: I used the Linux terminal to import PyAudio for python3.11 (which somehow worked). python3.11 -m pip install PyAudio worked. then in pycharm, I could use

source /.venv/bin/activate 
pip install /home/username/.cache/pip/wheel/something/something/something/something/PyAudio-0.2.14-cp311-cp311-linux_x86_64.whl

to actually install it. But now when I try to import it, it returns:

ImportError: libportaudio.so.2: cannot open shared object file: No such file or directory
Could not import the PyAudio C module 'pyaudio._portaudio'.

EDIT:

I‘ve since switched to arch linux, and can thus no longer use apt (instead I‘ll have to use pacman or yay). I also get a new error in the terminal

[thedisk@archlinux portaudio]$ pypy3 -m pip install pyaudio
Defaulting to user installation because normal site-packages is not writeable
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
  
  × Building wheel for pyaudio (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [26 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-pypy310
      creating build/lib.linux-x86_64-pypy310/pyaudio
      copying src/pyaudio/__init__.py -> build/lib.linux-x86_64-pypy310/pyaudio
      running build_ext
      building 'pyaudio._portaudio' extension
      creating build/temp.linux-x86_64-pypy310
      creating build/temp.linux-x86_64-pypy310/src
      creating build/temp.linux-x86_64-pypy310/src/pyaudio
      gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/local/include -I/usr/include -I/opt/pypy3/include/pypy3.10 -c src/pyaudio/device_api.c -o build/temp.linux-x86_64-pypy310/src/pyaudio/device_api.o
      gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/local/include -I/usr/include -I/opt/pypy3/include/pypy3.10 -c src/pyaudio/host_api.c -o build/temp.linux-x86_64-pypy310/src/pyaudio/host_api.o
      gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/local/include -I/usr/include -I/opt/pypy3/include/pypy3.10 -c src/pyaudio/init.c -o build/temp.linux-x86_64-pypy310/src/pyaudio/init.o
      gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/local/include -I/usr/include -I/opt/pypy3/include/pypy3.10 -c src/pyaudio/mac_core_stream_info.c -o build/temp.linux-x86_64-pypy310/src/pyaudio/mac_core_stream_info.o
      gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/local/include -I/usr/include -I/opt/pypy3/include/pypy3.10 -c src/pyaudio/main.c -o build/temp.linux-x86_64-pypy310/src/pyaudio/main.o
      gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/local/include -I/usr/include -I/opt/pypy3/include/pypy3.10 -c src/pyaudio/misc.c -o build/temp.linux-x86_64-pypy310/src/pyaudio/misc.o
      gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/local/include -I/usr/include -I/opt/pypy3/include/pypy3.10 -c src/pyaudio/stream.c -o build/temp.linux-x86_64-pypy310/src/pyaudio/stream.o
      gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/local/include -I/usr/include -I/opt/pypy3/include/pypy3.10 -c src/pyaudio/stream_io.c -o build/temp.linux-x86_64-pypy310/src/pyaudio/stream_io.o
      gcc -pthread -DNDEBUG -O2 -fPIC -I/usr/local/include -I/usr/include -I/opt/pypy3/include/pypy3.10 -c src/pyaudio/stream_lifecycle.c -o build/temp.linux-x86_64-pypy310/src/pyaudio/stream_lifecycle.o
      src/pyaudio/stream_lifecycle.c: In function ‘PyAudio_OpenStream’:
      src/pyaudio/stream_lifecycle.c:249:55: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘thread_id’
        249 |   stream->context.main_thread_id = PyThreadState_Get()->thread_id;
            |                                                       ^~
      error: command '/usr/bin/gcc' 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: ERROR: Failed to build installable wheels for some pyproject.toml based projects (pyaudio)

so as far as I understand, gcc is failing (or so I suppose).


Solution

  • I forgot what I did, but now it works. I think it was something with the venv, but I'm absolutely not sure