问题
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!
回答1:
$ brew install portaudio
$ pip install pyaudio
Some missing libraries and such that portaudio provides. Works for Python 2.7 (not sure about other versions)
回答2:
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.
回答3:
Following my comment above, this is similar to this answer, but since OP wasn't clear with it, I'm going to try again. (This is basically just a cut and paste from some notes I made to myself when I was doing this.)
- This is a build for 32-bit.
- Download pyaudio, and portaudio (I used 0.2.4, v19).
- cd portaudio
- make clean
- CC="gcc -arch i386" ./configure -enable-static
- make
- sudo make install (maybe not needed if you statically link to it).
- move portaudio into the PyAudio directory, that is:
- cd .. (out of portaudio)
- mv portaudio PyAudio/portaudio-v19 (note need the v19 here)
- cd into PyAudio and run:
- make sure you're in the virtual environment, ie,
source bin/activate
- python setup.py build –static-link
- python setup.py install
- make sure you're in the virtual environment, ie,
回答4:
You can install portaudio with $ sudo port install portaudio
and you can install pyaduio with mac installer from http://people.csail.mit.edu/hubert/pyaudio/
回答5:
this will install portaudio which is required for pyaudio:
sudo port install portaudio
next, look for the appropriate pyaudio macport for your version of python
port search pyaudio
suppose you are using python27, install pyaudio as such:
sudo port install py27-pyaudio
References:
How do I install PyAudio in virtualenv on Mac OS X 10.7
回答6:
Create a virtual env, activate it:
virtualenv env
env/bin/activate
Download PyAudio ( latest at the time ):
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:
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:
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!
回答7:
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.
回答8:
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.
回答9:
I recently needed this since I wanted to transcribe audio from mic using Google Cloud API. I have Python 3.7 installed in my Mac.
i386 Support is deprecated in recent OSx versions, so solving this requires modifying configure files.
- Download portaudio source code http://www.portaudio.com/download.html
- Download MacOSX10.12.sdk https://github.com/phracker/MacOSX-SDKs/releases and copy it in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
Add this lines to portaudio configure file, in order to include MacOSX10.13.sdk and MacOSX10.14.sdk so it doesn't fail
elif xcodebuild -version -sdk macosx10.13 Path >/dev/null 2>&1 ; then mac_version_min="-mmacosx-version-min=10.4" mac_sysroot="-isysroot `xcodebuild -version -sdk macosx10.13 Path`" elif xcodebuild -version -sdk macosx10.14 Path >/dev/null 2>&1 ; then mac_version_min="-mmacosx-version-min=10.4" mac_sysroot="-isysroot `xcodebuild -version -sdk macosx10.14 Path`" else as_fn_error $? "Could not find 10.5 to 10.14 SDK." "$LINENO" 5 fi
From your portaudio folder
./configure && make sudo make install
Download PyAudio source code (no wheel) https://pypi.org/project/PyAudio/#files
Add environment PORTAUDIO_PATH in your .bash_profile with the full path of your downloaded portaudio source code.
PORTAUDIO_PATH=/full/path/portaudio export PORTAUDIO_PATH
In your downloaded PyAudio source modify setup.py to rename folder portaudio-v19 with portaudio
portaudio_path = os.environ.get("PORTAUDIO_PATH", "./portaudio")
Install
python3 setup.py install --static-link
来源:https://stackoverflow.com/questions/14512741/pyaudio-portaudio-and-mac-10-7-5