环境:
Python 3.8.10
WSL2
问题描述:
尝试安装 pyaudio 时遇到的错误信息表示安装过程失败,原因是找不到 Python.h 头文件
error: subprocess-exited-with-error
× Building wheel for pyaudio (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [19 lines of output]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-38
creating build/lib.linux-x86_64-cpython-38/pyaudio
copying src/pyaudio/__init__.py -> build/lib.linux-x86_64-cpython-38/pyaudio
running build_ext
building 'pyaudio._portaudio' extension
creating build/temp.linux-x86_64-cpython-38
creating build/temp.linux-x86_64-cpython-38/src
creating build/temp.linux-x86_64-cpython-38/src/pyaudio
x86_64-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/usr/local/include -I/usr/include -I/mnt/e/work/metahuman-stream/myenv/include -I/usr/include/python3.8 -c src/pyaudio/device_api.c -o build/temp.linux-x86_64-cpython-38/src/pyaudio/device_api.o
In file included from src/pyaudio/device_api.c:1:
src/pyaudio/device_api.h:7:10: fatal error: Python.h: No such file or directory
7 | #include "Python.h"
| ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/x86_64-linux-gnu-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
解决方案:
1.在尝试安装 pyaudio 时遇到的错误信息表示安装过程失败,原因是找不到 Python.h 头文件。这通常意味着你的系统上缺少 Python 开发包。Python.h 文件是 Python 开发文件的一部分,对于那些包含 C 扩展的包(比如 pyaudio)来说是必需的。
如果你的Ubuntu版本较新,可能需要安装的是 python3-dev:
sudo apt-get update
sudo apt-get install python3-dev
2.要解决这个问题,你需要在Linux系统上安装相应的Python开发包。因为你使用的是Python 3.8,可以通过包管理器来安装所需文件。如果你使用的是基于Debian的系统(比如Ubuntu),可以这样做:
sudo apt-get update
sudo apt-get install python3.8-dev
3.再次安装pip3 install pyaudio 成功