简体   繁体   English

Pyaudio,portaudio和mac 10.7.5

[英]Pyaudio, portaudio and mac 10.7.5

I'm having trouble installing pyaudio correctly. 我在正确安装pyaudio时遇到问题。 I have a virtualenv set up for the project. 我为该项目设置了virtualenv。 I first tried to install portaudio: 我首先尝试安装portaudio:

sudo port install portaudio

which returns: 返回:

--->  Cleaning portaudio
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.

I assume that means it ran fine. 我认为这意味着它运行良好。 Then I tried: 然后我尝试了:

pip install pyaudio

Which returns: 哪个回报:

Downloading/unpacking pyaudio
Running setup.py egg_info for package pyaudio

warning: no files found matching '*.c' under directory 'test'
Installing collected packages: pyaudio
Running setup.py install for pyaudio
building '_portaudio' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -DMACOSX=1 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/_portaudiomodule.c -o build/temp.macosx-10.6-intel-2.7/src/_portaudiomodule.o -fno-strict-aliasing
src/_portaudiomodule.c:29:23: error: portaudio.h: No such file or directory
src/_portaudiomodule.c:33:25: error: pa_mac_core.h: No such file or directory
...

Is that first warning a problem? 这是第一个警告问题吗? I'm a bit surprised it's saying no file or directory for portaudio.h. 我有点惊讶它说没有portaudio.h的文件或目录。 Do I have to do something special to enable my port audio macport installation? 我是否必须做一些特殊的事情来启用我的端口音频macport安装?

Appreciate any help! 感谢任何帮助!

$ brew install portaudio
$ pip install pyaudio

Some missing libraries and such that portaudio provides. 一些丢失的库和portaudio提供的。 Works for Python 2.7 (not sure about other versions) 适用于Python 2.7(不确定其他版本)

How about the following: 以下内容如何:

$ sudo port install py27-pyaudio
Warning: port definitions are more than two weeks old, consider using selfupdate
--->  Computing dependencies for py27-pyaudio
--->  Fetching archive for py27-pyaudio
--->  Attempting to fetch py27-pyaudio-0.2.7_0.darwin_12.x86_64.tbz2 from http://lil.fr.packages.macports.org/py27-pyaudio
--->  Attempting to fetch py27-pyaudio-0.2.7_0.darwin_12.x86_64.tbz2.rmd160 from http://lil.fr.packages.macports.org/py27-pyaudio
--->  Installing py27-pyaudio @0.2.7_0
--->  Activating py27-pyaudio @0.2.7_0
--->  Cleaning py27-pyaudio
--->  Updating database of binaries: 100.0%
--->  Scanning binaries for linking errors: 100.0%
--->  No broken files found.
$ python -c "import pyaudio"
$

This works for me at least. 这至少对我有用。

Following my comment above, this is similar to this answer, but since OP wasn't clear with it, I'm going to try again. 根据我上面的评论,这与答案类似,但由于OP不清楚,我将再试一次。 (This is basically just a cut and paste from some notes I made to myself when I was doing this.) (这基本上只是我在做这个时给自己做的一些笔记的剪切和粘贴。)

  1. This is a build for 32-bit. 这是32位的构建。
  2. Download pyaudio, and portaudio (I used 0.2.4, v19). 下载pyaudio和portaudio(我使用的是0.2.4,v19)。
  3. cd portaudio cd portaudio
  4. make clean 干净
  5. CC="gcc -arch i386" ./configure -enable-static CC =“gcc -arch i386”./ configure -enable-static
  6. make 使
  7. sudo make install (maybe not needed if you statically link to it). sudo make install(如果你静态链接它可能不需要)。
  8. move portaudio into the PyAudio directory, that is: 将portaudio移动到PyAudio目录中,即:
    1. cd .. (out of portaudio) cd ..(在portaudio之外)
    2. mv portaudio PyAudio/portaudio-v19 (note need the v19 here) mv portaudio PyAudio / portaudio-v19(请注意这里需要v19)
  9. cd into PyAudio and run: cd进入PyAudio并运行:
    1. make sure you're in the virtual environment, ie, source bin/activate 确保你在虚拟环境中,即source bin/activate
    2. python setup.py build –static-link python setup.py build -static-link
    3. python setup.py install python setup.py安装

You can install portaudio with $ sudo port install portaudio 您可以使用$ sudo port install portaudio安装portaudio

and you can install pyaduio with mac installer from http://people.csail.mit.edu/hubert/pyaudio/ 你可以从http://people.csail.mit.edu/hubert/pyaudio/用mac安装程序安装pyaduio

this will install portaudio which is required for pyaudio: 这将安装pyaudio所需的portaudio:

sudo port install portaudio

next, look for the appropriate pyaudio macport for your version of python 接下来,为你的python版本寻找合适的pyaudio macport

port search pyaudio

suppose you are using python27, install pyaudio as such: 假设您正在使用python27,请安装pyaudio:

sudo port install py27-pyaudio

References: 参考文献:

How do I install PyAudio in virtualenv on Mac OS X 10.7 如何在Mac OS X 10.7上的virtualenv中安装PyAudio

Create a virtual env, activate it: 创建虚拟环境,激活它:

virtualenv env
env/bin/activate

Download PyAudio ( latest at the time ): 下载PyAudio(当时最新):

wget -c http://people.csail.mit.edu/hubert/pyaudio/packages/pyaudio-0.2.8.tar.gz
tar zxf pyaudio-0.2.8.tar.gz
cd PyAudio-0.2.8/

Unzip portaudio inside PyAudio folder, rename it to portaudio-v19 and build it: 在PyAudio文件夹中解压缩portaudio,将其重命名为portaudio-v19并构建它:

wget -c http://www.portaudio.com/archives/pa_stable_v19_20140130.tgz
tar zxf pa_stable_v19_20140130.tgz
mv portaudio portaudio-v19
cd portaudio-v19
./configure
make
cd ../

Back to PyAudio directory: 回到PyAudio目录:

export CFLAGS="-I `pwd`/portaudio-v19/include/ -L `pwd`/portaudio-v19/lib/.libs/"
python setup.py build --static-link
python setup.py install

Thats all! 就这样!

The crucial point is this command: 关键是这个命令:

export CFLAGS="-I `pwd`/portaudio-v19/include/ -L `pwd`/portaudio-v19/lib/.libs/"

which avoids no such file error. 这避免了这样的文件错误。

This solved my problem, thanks very much to @tuxdna. 这解决了我的问题,非常感谢@tuxdna。

The problem is that the pyaudio setup script ( setup.py ) assumes that all the necessary headers are in /usr/include . 问题是pyaudio设置脚本( setup.py )假定所有必需的头都在/usr/include That is why it works with HomeBrew, and not MacPorts, which typically (and cleanly) puts everything under /opt/local . 这就是为什么它适用于HomeBrew,而不是MacPorts,它通常(并且干净地)将所有内容放在/opt/local

PyAudio maintainers have relied on HomeBrew, and there is no option combination right now that allows for spelling out where to find the headers. PyAudio维护者依赖于HomeBrew,现在没有选项组合允许拼写出查找标题的位置。 At time of writing, the setup.py source code supports only default values for Mac OS X. 在撰写本文时, setup.py 源代码仅支持Mac OS X的默认值。

To work with MacPorts, it is cumbersome but enough to create two links for compiling: 要使用MacPorts,它很麻烦,但足以创建两个链接进行编译:

port install portaudio
sudo ln -s /opt/local/include/portaudio.h /usr/include
sudo ln -s /opt/local/include/pa_mac_core.h /usr/include
pip install --user pyaudio # Should now compile fine.

The links should probably be removed once the install is over. 安装结束后,可能应删除链接。

Tested on Mac OS X 10.10 with Python 2.7 installed with MacPorts. 在Mac OS X 10.10上测试,Python 2.7安装了MacPorts。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM