pyaudio安装不了的问题

使用
sudo pip install pyaudio
出现如下报错:


The directory '/home/drivesim/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/drivesim/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pyaudio
  Downloading https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Installing collected packages: pyaudio
  Running setup.py install for pyaudio ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-J4VKYR/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 /tmp/pip-jmDPq4-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    copying src/pyaudio.py -> build/lib.linux-x86_64-2.7
    running build_ext
    building '_portaudio' extension
    creating build/temp.linux-x86_64-2.7
    creating build/temp.linux-x86_64-2.7/src
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
    src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-J4VKYR/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 /tmp/pip-jmDPq4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-J4VKYR/pyaudio/
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

解决办法:
sudo apt-get install python-pyaudio python3-pyaudio



### 解决 PyAudio 安装过程中出现的错误 当尝试通过 `pip` 安装 PyAudio 时,可能会遇到诸如 “Failed building wheel for PyAudio” 或者找不到 `portaudio.h` 的问题。这类问题通常是因为缺少必要的编译工具或依赖项。 对于 Linux 用户,在基于 Red Hat/CentOS/Fedora 的发行版上可以通过执行命令来安装所需的 PortAudio 库及其开发文件: ```bash yum -y install portaudio portaudio-devel ``` 而在 Ubuntu 及其衍生版本,则应使用 APT 包管理器来进行相同操作: ```bash sudo apt-get update && sudo apt-get install portaudio19-dev ``` 如果是在 Windows 平台上遇到了类似的头文件缺失的问题,并且使用的 Python 版本为 3.7 或更高,由于官方暂时未提供这些版本下的预构建二进制包,因此建议前往第三方资源站点寻找对应系统的 `.whl` 文件并手动安装[^4]。例如可以从 LFD.UCI 提供的服务中查找适合当前环境配置的轮子文件(Wheel),下载完成后进入该文件所在路径下运行如下指令完成本地安装: ```cmd cd path\to\downloaded\wheel pip install filename.whl ``` 此外,确保已经安装了 Microsoft Visual C++ Build Tools 来支持从源码编译扩展模块也是很重要的一步[^5]。 ### 注意事项 - 对于不同操作系统平台需采用不同的方法处理依赖关系; - 当前环境下所用Python解释器的具体版本号也会影响最终解决方案的选择; - 如果可能的话尽量选用较新一点但仍受支持维护良好的Python版本以获得更好的兼容性和安全性保障;
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值