我正在运行Ubuntu 11.04,Python 2.7.1并想安装Pyaudio.所以我跑了,
$ sudo easy_install pyaudio
在终端和进程退出时出现以下错误消息,
Searching for pyaudio
Reading http://pypi.python.org/simple/pyaudio/
Reading http://people.csail.mit.edu/hubert/pyaudio/
Best match: pyaudio 0.2.4
Downloading http://people.csail.mit.edu/hubert/pyaudio/packages/pyaudio-0.2.4.tar.gz
Processing pyaudio-0.2.4.tar.gz
Running PyAudio-0.2.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-0Tetss/PyAudio-0.2.4/egg-dist-tmp-PYy9T8
In file included from /usr/include/python2.7/Python.h:8:0,
from src/_portaudiomodule.c:30:
/usr/include/python2.7/pyconfig.h:1155:0: warning: "_POSIX_C_SOURCE" redefined
/usr/include/features.h:214:0: note: this is the location of the previous definition
src/_portaudiomodule.c:31:23: fatal error: portaudio.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'gcc' failed with exit status 1
我不确定是要在askubuntu.com上发布这个,还是在stackoveflow中发布,但无论如何它都在stackoverflow中.另外我google了一下这个问题,通过安装python-dev找到了解决了一些问题.我已经安装了python-dev.可能出了什么问题?
UPDATE
以下是安装libportaudio-dev后出现的新错误,
Searching for pyaudio …
在macbook air 64位上运行以下代码,测试python 2.7和python 3.4上的代码
import speech_recognition as sr
r = sr.Recognizer()
with sr.microphone() as source:
audio = r.listen(source)
try:
print("You said " + r.recognize(audio))
except LookupError:
print("Could not understand audio")
Run Code Online (Sandbox Code Playgroud)
当我尝试python 2.7时,我不断收到以下错误:
Traceback (most recent call last):
File "star.py", line 3, in <module>
with sr.microphone() as source:
AttributeError: 'module' object has no attribute 'microphone'
Run Code Online (Sandbox Code Playgroud)
(star.py是我正在测试它的文件的名称)当我尝试python 3.4时,我不断收到以下错误:
Traceback (most recent call last):
File "star.py", line 1, in <module>
import speech_recognition as sr
ImportError: No module named 'speech_recognition'
Run Code Online (Sandbox Code Playgroud)
我已经下载了speech_recognition和pyaudio库,但错误的原因仍然没有找到我.请帮忙!