pythonpyaudioportaudio

pyaudio not working in linux in pycharm but work file in windows(dual boot)


i am new to linux and i am setting up my code (in code i trying to take audio input from user and changing it to text). ran into problem while installing pyaudio .when i try to install pyaudio(by pipwin install pyaudio) following showed

'''/home/sahil/.var/app/com.jetbrains.PyCharm-Community/data/python/lib/python3.9/site- 
 packages/pipwin/command.py:66: UserWarning: Found a non Windows system. Package 
 installation might not work.
   warn("Found a non Windows system. Package installation might not work.")
 Package `pyaudio` found in cache
 Downloading package . . .
 https://download.lfd.uci.edu/pythonlibs/x6hvwk7i/PyAudio-0.2.11-cp39-cp39-win_amd64.whl
 PyAudio-0.2.11-cp39-cp39-win_amd64.whl
 File /home/sahil/pipwin/PyAudio-0.2.11-cp39-cp39-win_amd64.whl already exists
 Defaulting to user installation because normal site-packages is not writeable
 ERROR: PyAudio-0.2.11-cp39-cp39-win_amd64.whl is not a supported wheel on this platform.
 Traceback (most recent call last):
   File "/home/sahil/.var/app/com.jetbrains.PyCharm-Community/data/python/bin/pipwin", 
 line 8, in <module>
     sys.exit(main())
   File "/home/sahil/.var/app/com.jetbrains.PyCharm- 
  Community/data/python/lib/python3.9/site-packages/pipwin/command.py", line 103, in main
     cache.install(package)
  File "/home/sahil/.var/app/com.jetbrains.PyCharm-Community/data/python/lib/python3.9/site-packages/pipwin/pipwin.py", line 301, in install
    subprocess.check_call([executable, "-m", "pip", "install", wheel_file])
  File "/usr/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python', '-m', 'pip', 'install', '/home/sahil/pipwin/PyAudio-0.2.11-cp39-cp39-win_amd64.whl']' returned non-zero exit status 1.

'''

and pip install shows following

Defaulting to user installation because normal site-packages is not writeable
Collecting pyaudio
  Using cached PyAudio-0.2.11.tar.gz (37 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/run/flatpak/app/com.jetbrains.PyCharm-Community/pip-install-02kj67hz/pyaudio_6aa4204f568e4240853b4fc67af97310/setup.py'"'"'; __file__='"'"'/run/flatpak/app/com.jetbrains.PyCharm-Community/pip-install-02kj67hz/pyaudio_6aa4204f568e4240853b4fc67af97310/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /run/flatpak/app/com.jetbrains.PyCharm-Community/pip-wheel-rqt57dbe
       cwd: /run/flatpak/app/com.jetbrains.PyCharm-Community/pip-install-02kj67hz/pyaudio_6aa4204f568e4240853b4fc67af97310/
  Complete output (16 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.9
  copying src/pyaudio.py -> build/lib.linux-x86_64-3.9
  running build_ext
  building '_portaudio' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/src
  x86_64-unknown-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -g -pipe -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 -g -pipe -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/include/python3.9 -I/usr/include/x86_64-linux-gnu/python3.9 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.9/src/_portaudiomodule.o
  src/_portaudiomodule.c:29:10: fatal error: portaudio.h: No such file or directory
     29 | #include "portaudio.h"
        |          ^~~~~~~~~~~~~
  compilation terminated.
  error: command '/usr/bin/x86_64-unknown-linux-gnu-gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for pyaudio
  Running setup.py clean for pyaudio
Failed to build pyaudio
Installing collected packages: pyaudio
    Running setup.py install for pyaudio ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/run/flatpak/app/com.jetbrains.PyCharm-Community/pip-install-02kj67hz/pyaudio_6aa4204f568e4240853b4fc67af97310/setup.py'"'"'; __file__='"'"'/run/flatpak/app/com.jetbrains.PyCharm-Community/pip-install-02kj67hz/pyaudio_6aa4204f568e4240853b4fc67af97310/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /run/flatpak/app/com.jetbrains.PyCharm-Community/pip-record-dygesdp8/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/sahil/.var/app/com.jetbrains.PyCharm-Community/data/python/include/python3.9/pyaudio
         cwd: /run/flatpak/app/com.jetbrains.PyCharm-Community/pip-install-02kj67hz/pyaudio_6aa4204f568e4240853b4fc67af97310/
    Complete output (18 lines):
    running install
    /usr/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
      warnings.warn(
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.9
    copying src/pyaudio.py -> build/lib.linux-x86_64-3.9
    running build_ext
    building '_portaudio' extension
    creating build/temp.linux-x86_64-3.9
    creating build/temp.linux-x86_64-3.9/src
    x86_64-unknown-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -g -pipe -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 -g -pipe -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/include/python3.9 -I/usr/include/x86_64-linux-gnu/python3.9 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-3.9/src/_portaudiomodule.o
    src/_portaudiomodule.c:29:10: fatal error: portaudio.h: No such file or directory
       29 | #include "portaudio.h"
          |          ^~~~~~~~~~~~~
    compilation terminated.
    error: command '/usr/bin/x86_64-unknown-linux-gnu-gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/run/flatpak/app/com.jetbrains.PyCharm-Community/pip-install-02kj67hz/pyaudio_6aa4204f568e4240853b4fc67af97310/setup.py'"'"'; __file__='"'"'/run/flatpak/app/com.jetbrains.PyCharm-Community/pip-install-02kj67hz/pyaudio_6aa4204f568e4240853b4fc67af97310/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /run/flatpak/app/com.jetbrains.PyCharm-Community/pip-record-dygesdp8/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/sahil/.var/app/com.jetbrains.PyCharm-Community/data/python/include/python3.9/pyaudio Check the logs for full command output

. and running the program show following error

Traceback (most recent call last): File "/home/sahil/PycharmProjects/funmate/main.py", line 77, in with speech.Microphone() as source: AttributeError: module 'speech_recognition' has no attribute 'Microphone'

some things that i already tried 1)install brew and do brew install portaudio 2)installing .wheel file

and last of all when i try to install pyaudio from linux terminal (sudo pip install pyaudio) it show already satisfy but in pycharm it show the above errors

thanks.


Solution

  • Like it says, you need the portaudio library installed. Assuming you are running Ubuntu, something like this should work:

    sudo apt install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0