在 macOS Big Sur 上安装 pyaudio 时出错

Error in installing pyaudio on macOS Big Sur

最近,我需要 pyaudio,我可以轻松地将其安装在 Linux machine 上。但是我的主计算机 运行s macOS 和我需要 运行 在我的 mac 上使用相同的代码。我刚刚这样做了:

sudo pip3 install pyaudio

我遇到了这些错误:

 ERROR: Command errored out with exit status 1:
   command: /usr/local/opt/python@3.9/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-y40lwe0s/pyaudio_a8cc0acc22ad46cc862ce836313544b3/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-y40lwe0s/pyaudio_a8cc0acc22ad46cc862ce836313544b3/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/tmp/pip-wheel-o2h5vchr
       cwd: /private/tmp/pip-install-y40lwe0s/pyaudio_a8cc0acc22ad46cc862ce836313544b3/
  Complete output (60 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-11-x86_64-3.9
  copying src/pyaudio.py -> build/lib.macosx-11-x86_64-3.9
  running build_ext
  building '_portaudio' extension
  creating build/temp.macosx-11-x86_64-3.9
  creating build/temp.macosx-11-x86_64-3.9/src
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DMACOSX=1 -I/usr/local/include -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/sqlite/include -I/usr/local/Cellar/python@3.9/3.9.0_4/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/_portaudiomodule.c -o build/temp.macosx-11-x86_64-3.9/src/_portaudiomodule.o
  src/_portaudiomodule.c:2278:3: warning: 'PyEval_InitThreads' is deprecated [-Wdeprecated-declarations]
    PyEval_InitThreads();
    ^
  /usr/local/Cellar/python@3.9/3.9.0_4/Frameworks/Python.framework/Versions/3.9/include/python3.9/ceval.h:130:1: note: 'PyEval_InitThreads' has been explicitly marked deprecated here
  Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
  ^
  /usr/local/Cellar/python@3.9/3.9.0_4/Frameworks/Python.framework/Versions/3.9/include/python3.9/pyport.h:508:54: note: expanded from macro 'Py_DEPRECATED'
  #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                       ^
  1 warning generated.
  clang -bundle -undefined dynamic_lookup build/temp.macosx-11-x86_64-3.9/src/_portaudiomodule.o -L/usr/local/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/sqlite/lib -lportaudio -o build/lib.macosx-11-x86_64-3.9/_portaudio.cpython-39-darwin.so
  installing to build/bdist.macosx-11-x86_64/wheel
  running install
  running install_lib
  creating build/bdist.macosx-11-x86_64
  creating build/bdist.macosx-11-x86_64/wheel
  copying build/lib.macosx-11-x86_64-3.9/_portaudio.cpython-39-darwin.so -> build/bdist.macosx-11-x86_64/wheel
  copying build/lib.macosx-11-x86_64-3.9/pyaudio.py -> build/bdist.macosx-11-x86_64/wheel
  running install_egg_info
  running egg_info
  writing src/PyAudio.egg-info/PKG-INFO
  writing dependency_links to src/PyAudio.egg-info/dependency_links.txt
  writing top-level names to src/PyAudio.egg-info/top_level.txt
  reading manifest file 'src/PyAudio.egg-info/SOURCES.txt'
  reading manifest template 'MANIFEST.in'
  writing manifest file 'src/PyAudio.egg-info/SOURCES.txt'
  Copying src/PyAudio.egg-info to build/bdist.macosx-11-x86_64/wheel/PyAudio-0.2.11-py3.9.egg-info
  running install_scripts
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/private/tmp/pip-install-y40lwe0s/pyaudio_a8cc0acc22ad46cc862ce836313544b3/setup.py", line 106, in <module>
      setup(name='PyAudio',
    File "/usr/local/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
      return distutils.core.setup(**attrs)
    File "/usr/local/Cellar/python@3.9/3.9.0_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/local/Cellar/python@3.9/3.9.0_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "/usr/local/Cellar/python@3.9/3.9.0_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/distutils/dist.py", line 985, in run_command
      cmd_obj.run()
    File "/usr/local/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 337, in run
      impl_tag, abi_tag, plat_tag = self.get_tag()
    File "/usr/local/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 260, in get_tag
      plat_name = get_platform(self.bdist_dir)
    File "/usr/local/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 52, in get_platform
      result = calculate_macosx_platform_tag(archive_root, result)
    File "/usr/local/lib/python3.9/site-packages/wheel/macosx_libfile.py", line 356, in calculate_macosx_platform_tag
      assert len(base_version) == 2
  AssertionError
  ----------------------------------------
  ERROR: Failed building wheel for pyaudio

我更新了 python 并更新了 XCode 以让它工作,但它没有做任何事情,我仍然收到错误。一堆库也发生了同样的事情,但我想如果我解决了我在这里遇到的问题,其他人也会没事的。

问题很容易就解决了。只需要从 python.org 安装 python 而不是 brew.

我今天也出现这样的错误,我通过brew安装portaudio工具解决了。

brew install portaudio
pip install pyaudio

它对我有用,所以我想这可能对你有帮助...

Collecting pyaudio
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz (37 kB)
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (setup.py) ... done
  Created wheel for pyaudio: filename=PyAudio-0.2.11-cp39-cp39-macosx_10_15_x86_64.whl size=23705 sha256=56e3a3fde06040f875ef5de2973fe474f6c83624524bc3ec76de55599a253b66
  Stored in directory: /Users/dapeng/Library/Caches/pip/wheels/2f/bd/fe/e61f992b5c64b27ac4dd31c3af467a800178eafba6fcb15815
Successfully built pyaudio
Installing collected packages: pyaudio
Successfully installed pyaudio-0.2.11