Pyaudio 在 Ubuntu 上安装失败

ech*_*cho 3 python pyaudio

Pyaudio 在 Ubuntu 上安装失败我有 ubuntu 18LTS python 2 和 python 3 pip 10

我根据在谷歌上找到的建议安装了 libportaudio2 和 libasound-dev。是不是因为我还需要安装其他库?

这是我尝试使用 sudo -H 标志但没有区别的错误。

sudo python -m pip install pyaudio
The directory '/home/ec2/.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/ec2/.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-install-wGfA8D/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-record-IYb2Y1/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 -fdebug-prefix-map=/build/python2.7-nbjU53/python2.7-2.7.15~rc1=. -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:10: fatal error: portaudio.h: No such file or directory
     #include "portaudio.h"
              ^~~~~~~~~~~~~
    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-install-wGfA8D/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-record-IYb2Y1/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-wGfA8D/pyaudio/
Run Code Online (Sandbox Code Playgroud)

Cor*_*erg 14

致命错误:portaudio.h:没有那个文件或目录

您缺少一些构建依赖项,因此编译失败。具体来说,错误显示它找不到portaudio.h,随portaudio19-dev包一起提供。

所以安装所需的头文件:

sudo apt-get install portaudio19-dev
Run Code Online (Sandbox Code Playgroud)

然后尝试您的 pip 安装。


Ard*_*ner 7

你可以试试

sudo apt-get install python-pyaudio
Run Code Online (Sandbox Code Playgroud)

在安装软件包之前尝试一下:

sudo apt-get install portaudio19-dev
Run Code Online (Sandbox Code Playgroud)

如果上述建议不起作用:

sudo apt-get install libjack-jackd2-dev portaudio19-dev
Run Code Online (Sandbox Code Playgroud)

并且pip install pyaudio应该有效。