pyaudio 在 pycharm 中的 linux 中不工作,但在 windows 中工作文件(双启动)

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

我是 linux 的新手,我正在设置我的代码(在代码中我试图从用户那里获取音频输入并将其更改为文本)。 运行 安装 pyaudio 时出现问题。当我尝试安装 pyaudio(by pipwin install pyaudio) 时显示

'''/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.

'''

并且 pip 安装显示如下

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

。 运行 程序显示以下错误

回溯(最近调用最后): 文件“/home/sahil/PycharmProjects/funmate/main.py”,第 77 行,位于 以 speech.Microphone() 作为来源: AttributeError: 模块 'speech_recognition' 没有属性 'Microphone'

我已经尝试过的一些事情 1) 安装 brew 并执行 brew install portaudio 2) 安装 .wheel 文件

最后,当我尝试从 linux 终端(sudo pip install pyaudio)安装 pyaudio 时,它显示已经满足,但在 pycharm 中显示上述错误

谢谢。

如其所说,您需要安装 portaudio 库。假设你是 运行 Ubuntu,这样的事情应该有效:

sudo apt install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0