Python尝试安装 pyaudio 时遇到的错误信息表示安装过程失败,原因是找不到 Python.h 头文件

环境:

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 成功
在这里插入图片描述

最近更新

  1. TCP协议是安全的吗?

    2024-05-11 03:38:03       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-11 03:38:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-11 03:38:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-11 03:38:03       20 阅读

热门阅读

  1. Mysql数据库基础知识(2)

    2024-05-11 03:38:03       6 阅读
  2. Oracle 19C 传输表空间之-Windows 至 Linux

    2024-05-11 03:38:03       10 阅读
  3. 开源模型应用落地-模型记忆增强-概念篇(一)

    2024-05-11 03:38:03       10 阅读
  4. (数据结构)快速了解时间复杂度和空间复杂度

    2024-05-11 03:38:03       10 阅读
  5. QT--5

    QT--5

    2024-05-11 03:38:03      9 阅读
  6. 网络面试题目

    2024-05-11 03:38:03       11 阅读
  7. MySQL数据库——23.元数据

    2024-05-11 03:38:03       10 阅读
  8. android 获取唯一设备id

    2024-05-11 03:38:03       10 阅读