Pyaudio, portaudio and mac 10.7.5

2019-03-30 16:51发布

I'm having trouble installing pyaudio correctly. I have a virtualenv set up for the project. I first tried to install 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. Do I have to do something special to enable my port audio macport installation?

Appreciate any help!

8条回答
混吃等死
2楼-- · 2019-03-30 17:45

The problem is that the pyaudio setup script (setup.py) assumes that all the necessary headers are in /usr/include. That is why it works with HomeBrew, and not MacPorts, which typically (and cleanly) puts everything under /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. At time of writing, the setup.py source code supports only default values for Mac OS X.

To work with MacPorts, it is cumbersome but enough to create two links for compiling:

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.

查看更多
再贱就再见
3楼-- · 2019-03-30 17:58

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.

查看更多
登录 后发表回答