当前位置: 首页 > 工具软件 > PortAudio > 使用案例 >

[Mac M1] 错误xcrun: error: (/Library/Developer/CommandLineTools) || #include “portaudio.h“

慕逸仙
2023-12-01

目录

错误信息1-xcrun

错误信息2-pyaudio.h

错误信息1-xcrun

     gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Users/harry/miniforge3/envs/py37/include -arch x86_64 -I/Users/harry/miniforge3/envs/py37/include -arch x86_64 -DMACOS=1 -I/usr/local/include -I/usr/include -I/opt/homebrew/include -I/usr/local/opt/portaudio/include/ -I/Users/harry/miniforge3/envs/py37/include/python3.7m -c src/pyaudio/device_api.c -o build/temp.macosx-10.9-x86_64-cpython-37/src/pyaudio/device_api.o
      xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
      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: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects

问题描述

利用python安装pyaudio时候出现的错误。

主要看错误是不是“xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun”

解决方法

xcode-select --install

错误信息2-pyaudio.h

pip install pyaudio      
            Collecting pyaudio
              Using cached PyAudio-0.2.12.tar.gz (42 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
              ╰─> [16 lines of output]
                  running bdist_wheel
                  running build
                  running build_py
                  creating build
                  creating build/lib.macosx-10.9-universal2-cpython-39
                  copying src/pyaudio.py -> build/lib.macosx-10.9-universal2-cpython-39
                  running build_ext
                  building '_portaudio' extension
                  creating build/temp.macosx-10.9-universal2-cpython-39
                  creating build/temp.macosx-10.9-universal2-cpython-39/src
                  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DMACOSX=1 -I/usr/local/include -I/usr/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/_portaudiomodule.c -o build/temp.macosx-10.9-universal2-cpython-39/src/_portaudiomodule.o
                  src/_portaudiomodule.c:31:10: fatal error: 'portaudio.h' file not found
                  #include "portaudio.h"
                           ^~~~~~~~~~~~~
                  1 error generated.
                  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: Could not build wheels for pyaudio, which is required to install pyproject.toml-based projects

主要的错误信息是“ #include "portaudio.h"
                           ^~~~~~~~~~~~~
                  1 error generated.”

解决方法:

1. 安装portaudio

brew install portaudio

2. 连接portaudio

brew link portaudio

3. 查看安装的路径

#check the path of portaudio you installed
brew --prefix portaudio

4. 安装pyaudio

方法一: 替换下面的portaudio路径。直接执行


# replace the portaudio path with yours
pip install --global-option='build_ext' --global-option='<portaudio path>/include' --global-option='<portaudio path>/lib' pyaudio

方法二:创建下面文件

sudo nano $HOME/.pydistutils.cfg

粘贴并且替换路径

[build_ext]
include_dirs=<PATH FROM STEP 3>/include/
library_dirs=<PATH FROM STEP 3>/lib/

执行下面命令

pip install pyaudio

参考资料

pip - Unable to install PyAudio on M1 Mac [PortAudio already installed] - Stack OverflowApple macOS (M1Pro)上成功安装PyAudio - 知乎

 类似资料: