Python 安装pyaudio时,pip在/usr/local/include中找不到portaudio.h

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33513522/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:29:34  来源:igfitidea点击:

when installing pyaudio, pip cannot find portaudio.h in /usr/local/include

pythonmacospyaudio

提问by Xun Jian

I'm using mac osx 10.10 As the PyAudio Homepage said, I install the PyAudio using

我使用的是 mac osx 10.10 正如 PyAudio Homepage 所说,我安装 PyAudio 使用

brew install portaudio 
pip install pyaudio

the installation of portaudio seems successful, I can find headers and libs in /usr/local/include and /usr/local/lib but when I try to install pyaudio, it gives me an error that

portaudio 的安装似乎成功了,我可以在 /usr/local/include 和 /usr/local/lib 中找到头文件和库,但是当我尝试安装 pyaudio 时,它给了我一个错误

src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
         ^
1 error generated.
error: command 'cc' failed with exit status 1

actually it is in /usr/local/include why can't it find the file? some answers to similar questions are not working for me(like using virtualenv, or compile it manually), and I want to find a simple way to solve this.

实际上它在 /usr/local/include 为什么找不到文件?类似问题的一些答案对我不起作用(例如使用 virtualenv 或手动编译),我想找到一种简单的方法来解决这个问题。

采纳答案by fukudama

Since pyAudiohas portAudioas a dependency, you first have to install portaudio.

由于pyAudiohasportAudio作为依赖项,您首先必须安装 portaudio。

brew install portaudio

Then try: pip install pyAudio. If the problem persists after installing portAudio, you can specify the directory path where the compiler will be able to find the source programs (e.g: portaudio.h). Since the headers should be in the /usr/local/includedirectory:

然后尝试:pip install pyAudio。如果安装后问题仍然存在portAudio,您可以指定编译器能够找到源程序的目录路径(例如:)portaudio.h。由于标题应该在/usr/local/include目录中:

pip install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio

回答by Eric Saund

For me on 10.10.5 the paths were under /opt/local. I had to add /opt/local/bin to my /etc/paths file. And the command line that worked was

对于 10.10.5 的我来说,路径在 /opt/local 下。我不得不将 /opt/local/bin 添加到我的 /etc/paths 文件中。工作的命令行是

sudo pip install --global-option='build_ext' --global-option='-I/opt/local/include' --global-option='-L/opt/local/lib' pyaudio

sudo pip install --global-option='build_ext' --global-option='-I/opt/local/include' --global-option='-L/opt/local/lib' pyaudio

回答by chaitanya

You have to install portaudio first then link that file. Only then you can find that header file (i.e, portaudio.h). To install portaudio in mac by using HomeBrewprogram use following commands.

您必须先安装 portaudio,然后链接该文件。只有这样,您才能找到该头文件(即 portaudio.h)。要使用HomeBrew程序在 mac 中安装 portaudio,请使用以下命令。

brew install portaudio
brew link portaudio
pip install pyaudio

sudo is not needed if you're admin. We should refrain using sudo as it messes up lots of permissions.

如果您是管理员,则不需要 sudo。我们应该避免使用 sudo,因为它会混淆很多权限。

回答by timest

on Centos:

在 Centos 上:

yum install -y portaudio portaudio-devel && pip install pyaudio

回答by PartialOrder

Just for the record for folks using MacPorts and not Homebrew:

仅供使用 MacPorts 而不是 Homebrew 的人的记录:

$ [sudo] port install portaudio
$ pip install pyaudio --global-option="build_ext"  --global-option="-I/opt/local/include" --global-option="-L/opt/local/lib"

回答by Harry

First you can use brew to install portaudio .

首先你可以使用 brew 来安装 portaudio 。

brew install portaudio

酿造安装portaudio

Then try to find the portaudio path sudo find / -name "portaudio.h"

然后尝试找到portaudio路径 sudo find / -name "portaudio.h"

In my case it is /usr/local/Cellar/portaudio/19.6.0/include.

就我而言,它是/usr/local/Cellar/portaudio/19.6.0/include.

Run the below to install pyaudio

运行以下命令安装 pyaudio

pip install --global-option='build_ext' --global-option='-I/usr/local/Cellar/portaudio/19.6.0/include' --global-option='-L/usr/local/Cellar/portaudio/19.6.0/lib' pyaudio

pip install --global-option='build_ext' --global-option='-I/usr/local/Cellar/portaudio/19.6.0/include' --global-option='-L/usr/local/Cellar /portaudio/19.6.0/lib' pyaudio

回答by danielrosero

On Raspbian:

在树莓派上:

sudo apt-get install python-pyaudio

回答by Robbie Matthews

On Ubuntu builds:

在 Ubuntu 上:

sudo apt-get install python-pyaudio

For Python3:

对于 Python3:

sudo apt-get install python3-pyaudio

回答by Dixit

If you are using anaconda/miniconda to manage your python environments then

如果您使用 anaconda/miniconda 来管理您的 Python 环境,那么

conda install pyaudio

conda install pyaudio

installs portaudioat the same time as pyaudio

安装portaudio在同一时间pyaudio

The following NEW packages will be INSTALLED:

  portaudio          pkgs/main/osx-64::portaudio-19.6.0-h647c56a_4
  pyaudio            pkgs/main/osx-64::pyaudio-0.2.11-py37h1de35cc_2