在Mac上安装pyaudio

时间:2019-01-03 08:23:29

标签: python macos pyaudio

我正在尝试在系统上安装pyaudio。

系统规范:macOS Mojava

版本:10.14.2 (18C54)

我得到的错误是:

    Collecting pyaudio
  Using cached https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: pyaudio
  Running setup.py bdist_wheel for pyaudio ... error
  Complete output from command /Users/dsnanaware/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/r7/64j7w40s1fn8bmdkblq1pbym0000gn/T/pip-install-yro3wf2m/pyaudio/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/var/folders/r7/64j7w40s1fn8bmdkblq1pbym0000gn/T/pip-wheel-3d4sruhv --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.7-x86_64-3.6
  copying src/pyaudio.py -> build/lib.macosx-10.7-x86_64-3.6
  running build_ext
  building '_portaudio' extension
  creating build/temp.macosx-10.7-x86_64-3.6
  creating build/temp.macosx-10.7-x86_64-3.6/src
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/dsnanaware/anaconda3/include -arch x86_64 -I/Users/dsnanaware/anaconda3/include -arch x86_64 -DMACOSX=1 -I/Users/dsnanaware/anaconda3/include/python3.6m -c src/_portaudiomodule.c -o build/temp.macosx-10.7-x86_64-3.6/src/_portaudiomodule.o
  src/_portaudiomodule.c:27:19: fatal error: stdio.h: No such file or directory
   #include <stdio.h>
                     ^
  compilation terminated.
  error: command 'gcc' failed with exit status 1

  ----------------------------------------
  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
    Complete output from command /Users/dsnanaware/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/r7/64j7w40s1fn8bmdkblq1pbym0000gn/T/pip-install-yro3wf2m/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/r7/64j7w40s1fn8bmdkblq1pbym0000gn/T/pip-record-4xqsbegf/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.7-x86_64-3.6
    copying src/pyaudio.py -> build/lib.macosx-10.7-x86_64-3.6
    running build_ext
    building '_portaudio' extension
    creating build/temp.macosx-10.7-x86_64-3.6
    creating build/temp.macosx-10.7-x86_64-3.6/src
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/dsnanaware/anaconda3/include -arch x86_64 -I/Users/dsnanaware/anaconda3/include -arch x86_64 -DMACOSX=1 -I/Users/dsnanaware/anaconda3/include/python3.6m -c src/_portaudiomodule.c -o build/temp.macosx-10.7-x86_64-3.6/src/_portaudiomodule.o
    src/_portaudiomodule.c:27:19: fatal error: stdio.h: No such file or directory
     #include <stdio.h>
                       ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

    ----------------------------------------
Command "/Users/dsnanaware/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/r7/64j7w40s1fn8bmdkblq1pbym0000gn/T/pip-install-yro3wf2m/pyaudio/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/r7/64j7w40s1fn8bmdkblq1pbym0000gn/T/pip-record-4xqsbegf/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/r7/64j7w40s1fn8bmdkblq1pbym0000gn/T/pip-install-yro3wf2m/pyaudio/

我试图解决此问题的方法:

  1. brew install portaudio
  2. pip install pyaudio

但是即使尝试了此方法,我仍然遇到相同的错误。

有人可以帮助我解决这个错误吗?

谢谢!!

2 个答案:

答案 0 :(得分:0)

解决方案:

brew update
brew install portaudio
brew link --overwrite portaudio
pip install pyaudio

https://medium.com/@moon_is_beautiful/when-cant-install-pyaudio-with-pip-190973840dbf

答案 1 :(得分:0)

对我来说,它遵循了这个要旨

https://gist.github.com/jiaaro/9767512210a1d80a8a0d

使用自制程序(或您选择的方法)安装portaudio

brew install portaudio

使用portaudio安装的include和lib目录创建$ HOME / .pydistutils.cfg:

[build_ext]
include_dirs=/Users/jrobert1271/homebrew/Cellar/portaudio/19.20140130/include/
library_dirs=/Users/jrobert1271/homebrew/Cellar/portaudio/19.20140130/lib/

然后在您的virtualenv中:

 pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio